| @@ -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','templates' ]; | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Required keys for components. |
| 31 | 31 | * |
| @@ -62,8 +62,29 @@ | ||
| 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 | + /** | |
| 80 | + * Holds the registered templates. | |
| 81 | + * | |
| 82 | + * @var array | |
| 83 | + */ | |
| 84 | + private static $templates = []; | |
| 85 | + | |
| 86 | + /** | |
| 66 | 87 | * The Component_Registry object. |
| 67 | 88 | * |
| 68 | 89 | * @var object Component_Registry |
| 69 | 90 | */ |
| @@ -129,13 +150,35 @@ | ||
| 129 | 150 | } |
| 130 | 151 | self::$blocks[ $data['key'] ] = $data; |
| 131 | 152 | break; |
| 132 | 153 | |
| 133 | - case 'page': | |
| 134 | - if ( ! empty( self::$pages[ $data['key'] ] ) ) { | |
| 154 | + case 'page': | |
| 155 | + if ( ! empty( self::$pages[ $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 'header': | |
| 162 | + if ( ! empty( self::$headers[ $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; | |
| 168 | + case 'footer': | |
| 169 | + if ( ! empty( self::$footers[ $data['key'] ] ) ) { | |
| 170 | + /* translators: %s: The component's unique key. */ | |
| 171 | + throw new InvalidArgumentException( sprintf( esc_html__( 'The %s section is already registered.', 'blockspare' ), $data['key'] ) ); | |
| 172 | + } | |
| 173 | + self::$pages[ $data['key'] ] = $data; | |
| 174 | + break; | |
| 175 | + | |
| 176 | + case 'templates': | |
| 177 | + if ( ! empty( self::$templates[ $data['key'] ] ) ) { | |
| 135 | 178 | /* translators: %s: The component's unique key. */ |
| 136 | 179 | throw new InvalidArgumentException( sprintf( esc_html__( 'The %s section is already registered.', 'blockspare' ), $data['key'] ) ); |
| 137 | - } | |
| 180 | + } | |
| 138 | 181 | self::$pages[ $data['key'] ] = $data; |
| 139 | 182 | break; |
| 140 | 183 | |
| 141 | 184 | default: |
| @@ -191,14 +234,37 @@ | ||
| 191 | 234 | } |
| 192 | 235 | unset( self::$blocks[ $key ] ); |
| 193 | 236 | break; |
| 194 | 237 | |
| 195 | - case 'page': | |
| 196 | - if ( empty( self::$pages[ $key ] ) ) { | |
| 238 | + case 'page': | |
| 239 | + if ( empty( self::$pages[ $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::$pages[ $key ] ); | |
| 244 | + break; | |
| 245 | + case 'header': | |
| 246 | + if ( empty( self::$headers[ $key ] ) ) { | |
| 247 | + /* translators: The requested components unique key. */ | |
| 248 | + throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); | |
| 249 | + } | |
| 250 | + unset( self::$headers[ $key ] ); | |
| 251 | + break; | |
| 252 | + | |
| 253 | + case 'footer': | |
| 254 | + if ( empty( self::$footers[ $key ] ) ) { | |
| 255 | + /* translators: The requested components unique key. */ | |
| 256 | + throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); | |
| 257 | + } | |
| 258 | + unset( self::$footers[ $key ] ); | |
| 259 | + break; | |
| 260 | + | |
| 261 | + case 'templates': | |
| 262 | + if ( empty( self::$templates[ $key ] ) ) { | |
| 197 | 263 | /* translators: The requested components unique key. */ |
| 198 | 264 | throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); |
| 199 | 265 | } |
| 200 | - unset( self::$pages[ $key ] ); | |
| 266 | + unset( self::$templates[ $key ] ); | |
| 201 | 267 | break; |
| 202 | 268 | } |
| 203 | 269 | |
| 204 | 270 | } |
| @@ -248,9 +314,30 @@ | ||
| 248 | 314 | /* translators: The requested components unique key. */ |
| 249 | 315 | throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); |
| 250 | 316 | } |
| 251 | 317 | return self::$pages[ $key ]; |
| 318 | + | |
| 319 | + case 'header': | |
| 320 | + if ( empty( self::$headers[ $key ] ) ) { | |
| 321 | + /* translators: The requested components unique key. */ | |
| 322 | + throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); | |
| 323 | + } | |
| 324 | + return self::$headers[ $key ]; | |
| 252 | 325 | |
| 326 | + case 'footer': | |
| 327 | + if ( empty( self::$footers[ $key ] ) ) { | |
| 328 | + /* translators: The requested components unique key. */ | |
| 329 | + throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); | |
| 330 | + } | |
| 331 | + return self::$footers[ $key ]; | |
| 332 | + | |
| 333 | + case 'templates': | |
| 334 | + if ( empty( self::$templates[ $key ] ) ) { | |
| 335 | + /* translators: The requested components unique key. */ | |
| 336 | + throw new Exception( sprintf( esc_html__( 'The %s section is not registered.', 'blockspare' ), $key ) ); | |
| 337 | + } | |
| 338 | + return self::$templates[ $key ]; | |
| 339 | + | |
| 253 | 340 | default: |
| 254 | 341 | /* translators: This function name. Will always be Blockspare\Layouts\Component_Registry::get(). */ |
| 255 | 342 | throw new InvalidArgumentException( sprintf( esc_html__( 'You must supply a valid component type in %s.', 'blockspare' ), __METHOD__ ) ); |
| 256 | 343 | } |
| @@ -290,6 +377,29 @@ | ||
| 290 | 377 | * @return array |
| 291 | 378 | */ |
| 292 | 379 | public static function pages() { |
| 293 | 380 | return self::$pages; |
| 381 | + } | |
| 382 | + | |
| 383 | + /** | |
| 384 | + * Returns the registered headers. | |
| 385 | + * | |
| 386 | + * @return array | |
| 387 | + */ | |
| 388 | + public static function headers() { | |
| 389 | + return self::$headers; | |
| 390 | + } | |
| 391 | + | |
| 392 | + /** | |
| 393 | + * Returns the registered footers. | |
| 394 | + * | |
| 395 | + * @return array | |
| 396 | + */ | |
| 397 | + public static function footers() { | |
| 398 | + return self::$footers; | |
| 399 | + } | |
| 400 | + | |
| 401 | + | |
| 402 | + public static function templates() { | |
| 403 | + return self::$templates; | |
| 294 | 404 | } |
| 295 | 405 | } |