| @@ -23,9 +23,9 @@ | ||
| 23 | 23 | * Supported component types. |
| 24 | 24 | * |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - private static $supported_component_types = [ 'layout', 'section','block','page' ]; | |
| 27 | + private static $supported_component_types = [ 'layout', 'section','block','page','header','footer' ]; | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Required keys for components. |
| 31 | 31 | * |
| @@ -62,8 +62,22 @@ | ||
| 62 | 62 | */ |
| 63 | 63 | private static $pages = []; |
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | + * Holds the registered headers. | |
| 67 | + * | |
| 68 | + * @var array | |
| 69 | + */ | |
| 70 | + private static $headers = []; | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * Holds the registered footers. | |
| 74 | + * | |
| 75 | + * @var array | |
| 76 | + */ | |
| 77 | + private static $footers = []; | |
| 78 | + | |
| 79 | + /** | |
| 66 | 80 | * The Component_Registry object. |
| 67 | 81 | * |
| 68 | 82 | * @var object Component_Registry |
| 69 | 83 | */ |
| @@ -129,15 +143,29 @@ | ||
| 129 | 143 | } |
| 130 | 144 | self::$blocks[ $data['key'] ] = $data; |
| 131 | 145 | break; |
| 132 | 146 | |
| 133 | - case 'page': | |
| 134 | - if ( ! empty( self::$pages[ $data['key'] ] ) ) { | |
| 135 | - /* translators: %s: The component's unique key. */ | |
| 136 | - throw new InvalidArgumentException( sprintf( esc_html__( 'The %s section is already registered.', 'blockspare' ), $data['key'] ) ); | |
| 147 | + case 'page': | |
| 148 | + if ( ! empty( self::$pages[ $data['key'] ] ) ) { | |
| 149 | + /* translators: %s: The component's unique key. */ | |
| 150 | + throw new InvalidArgumentException( sprintf( esc_html__( 'The %s section is already registered.', 'blockspare' ), $data['key'] ) ); | |
| 137 | 151 | } |
| 138 | - self::$pages[ $data['key'] ] = $data; | |
| 139 | - break; | |
| 152 | + self::$pages[ $data['key'] ] = $data; | |
| 153 | + break; | |
| 154 | + case 'header': | |
| 155 | + if ( ! empty( self::$headers[ $data['key'] ] ) ) { | |
| 156 | + /* translators: %s: The component's unique key. */ | |
| 157 | + throw new InvalidArgumentException( sprintf( esc_html__( 'The %s section is already registered.', 'blockspare' ), $data['key'] ) ); | |
| 158 | + } | |
| 159 | + self::$pages[ $data['key'] ] = $data; | |
| 160 | + break; | |
| 161 | + case 'footer': | |
| 162 | + if ( ! empty( self::$footers[ $data['key'] ] ) ) { | |
| 163 | + /* translators: %s: The component's unique key. */ | |
| 164 | + throw new InvalidArgumentException( sprintf( esc_html__( 'The %s section is already registered.', 'blockspare' ), $data['key'] ) ); | |
| 165 | + } | |
| 166 | + self::$pages[ $data['key'] ] = $data; | |
| 167 | + break; | |
| 140 | 168 | |
| 141 | 169 | default: |
| 142 | 170 | /* translators: %s: This functions name. Will always be Blockspare\Layouts\Component_Registry::add(). */ |
| 143 | 171 | throw new InvalidArgumentException( sprintf( esc_html__( 'You must supply a valid component type in %s.', 'blockspare' ), __METHOD__ ) ); |
| @@ -191,15 +219,30 @@ | ||
| 191 | 219 | } |
| 192 | 220 | unset( self::$blocks[ $key ] ); |
| 193 | 221 | break; |
| 194 | 222 | |
| 195 | - case 'page': | |
| 196 | - if ( empty( self::$pages[ $key ] ) ) { | |
| 197 | - /* translators: The requested components unique key. */ | |
| 223 | + case 'page': | |
| 224 | + if ( empty( self::$pages[ $key ] ) ) { | |
| 225 | + /* translators: The requested components unique key. */ | |
| 226 | + throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); | |
| 227 | + } | |
| 228 | + unset( self::$pages[ $key ] ); | |
| 229 | + break; | |
| 230 | + case 'header': | |
| 231 | + if ( empty( self::$headers[ $key ] ) ) { | |
| 232 | + /* translators: The requested components unique key. */ | |
| 198 | 233 | throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); |
| 199 | - } | |
| 200 | - unset( self::$pages[ $key ] ); | |
| 201 | - break; | |
| 234 | + } | |
| 235 | + unset( self::$headers[ $key ] ); | |
| 236 | + break; | |
| 237 | + | |
| 238 | + case 'footer': | |
| 239 | + if ( empty( self::$footers[ $key ] ) ) { | |
| 240 | + /* translators: The requested components unique key. */ | |
| 241 | + throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); | |
| 242 | + } | |
| 243 | + unset( self::$footers[ $key ] ); | |
| 244 | + break; | |
| 202 | 245 | } |
| 203 | 246 | |
| 204 | 247 | } |
| 205 | 248 | |
| @@ -248,9 +291,23 @@ | ||
| 248 | 291 | /* translators: The requested components unique key. */ |
| 249 | 292 | throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); |
| 250 | 293 | } |
| 251 | 294 | return self::$pages[ $key ]; |
| 295 | + | |
| 296 | + case 'header': | |
| 297 | + if ( empty( self::$headers[ $key ] ) ) { | |
| 298 | + /* translators: The requested components unique key. */ | |
| 299 | + throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); | |
| 300 | + } | |
| 301 | + return self::$headers[ $key ]; | |
| 252 | 302 | |
| 303 | + case 'footer': | |
| 304 | + if ( empty( self::$footers[ $key ] ) ) { | |
| 305 | + /* translators: The requested components unique key. */ | |
| 306 | + throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); | |
| 307 | + } | |
| 308 | + return self::$footers[ $key ]; | |
| 309 | + | |
| 253 | 310 | default: |
| 254 | 311 | /* translators: This function name. Will always be Blockspare\Layouts\Component_Registry::get(). */ |
| 255 | 312 | throw new InvalidArgumentException( sprintf( esc_html__( 'You must supply a valid component type in %s.', 'blockspare' ), __METHOD__ ) ); |
| 256 | 313 | } |
| @@ -290,6 +347,24 @@ | ||
| 290 | 347 | * @return array |
| 291 | 348 | */ |
| 292 | 349 | public static function pages() { |
| 293 | 350 | return self::$pages; |
| 351 | + } | |
| 352 | + | |
| 353 | + /** | |
| 354 | + * Returns the registered headers. | |
| 355 | + * | |
| 356 | + * @return array | |
| 357 | + */ | |
| 358 | + public static function headers() { | |
| 359 | + return self::$headers; | |
| 360 | + } | |
| 361 | + | |
| 362 | + /** | |
| 363 | + * Returns the registered footers. | |
| 364 | + * | |
| 365 | + * @return array | |
| 366 | + */ | |
| 367 | + public static function footers() { | |
| 368 | + return self::$footers; | |
| 294 | 369 | } |
| 295 | 370 | } |