@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | * @return self |
| 102 | 102 | * @throws App_Initialization_Exception Code 2 |
| 103 | 103 | */ |
| 104 | - public function set_container( DI_Container $container ): self { |
|
| 105 | - if ( self::$container !== null ) { |
|
| 104 | + public function set_container(DI_Container $container): self { |
|
| 105 | + if (self::$container !== null) { |
|
| 106 | 106 | throw App_Initialization_Exception::di_container_exists(); |
| 107 | 107 | } |
| 108 | 108 | |
@@ -117,12 +117,12 @@ discard block |
||
| 117 | 117 | * @return self |
| 118 | 118 | * @throws App_Initialization_Exception Code 5 |
| 119 | 119 | */ |
| 120 | - public function set_app_config( array $settings ): self { |
|
| 121 | - if ( self::$app_config !== null ) { |
|
| 120 | + public function set_app_config(array $settings): self { |
|
| 121 | + if (self::$app_config !== null) { |
|
| 122 | 122 | throw App_Initialization_Exception::app_config_exists(); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - self::$app_config = new App_Config( apply_filters( Hooks::APP_INIT_CONFIG_VALUES, $settings ) ); |
|
| 125 | + self::$app_config = new App_Config(apply_filters(Hooks::APP_INIT_CONFIG_VALUES, $settings)); |
|
| 126 | 126 | return $this; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | * @param \PinkCrab\Perique\Services\Registration\Registration_Service $registration |
| 133 | 133 | * @return self |
| 134 | 134 | */ |
| 135 | - public function set_registration_services( Registration_Service $registration ): self { |
|
| 136 | - if ( $this->registration !== null ) { |
|
| 135 | + public function set_registration_services(Registration_Service $registration): self { |
|
| 136 | + if ($this->registration !== null) { |
|
| 137 | 137 | throw App_Initialization_Exception::registration_exists(); |
| 138 | 138 | } |
| 139 | 139 | $this->registration = $registration; |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | * @param \PinkCrab\Loader\Hook_Loader $loader |
| 147 | 147 | * @return self |
| 148 | 148 | */ |
| 149 | - public function set_loader( Hook_Loader $loader ): self { |
|
| 150 | - if ( $this->loader !== null ) { |
|
| 149 | + public function set_loader(Hook_Loader $loader): self { |
|
| 150 | + if ($this->loader !== null) { |
|
| 151 | 151 | throw App_Initialization_Exception::loader_exists(); |
| 152 | 152 | } |
| 153 | 153 | $this->loader = $loader; |
@@ -162,11 +162,11 @@ discard block |
||
| 162 | 162 | * @return self |
| 163 | 163 | * @throws App_Initialization_Exception Code 1 |
| 164 | 164 | */ |
| 165 | - public function container_config( callable $callback ): self { |
|
| 166 | - if ( self::$container === null ) { |
|
| 165 | + public function container_config(callable $callback): self { |
|
| 166 | + if (self::$container === null) { |
|
| 167 | 167 | throw App_Initialization_Exception::requires_di_container(); |
| 168 | 168 | } |
| 169 | - $callback( self::$container ); |
|
| 169 | + $callback(self::$container); |
|
| 170 | 170 | return $this; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -177,17 +177,17 @@ discard block |
||
| 177 | 177 | * @return self |
| 178 | 178 | * @throws App_Initialization_Exception Code 3 |
| 179 | 179 | */ |
| 180 | - public function registration_middleware( Registration_Middleware $middleware ): self { |
|
| 181 | - if ( $this->registration === null ) { |
|
| 180 | + public function registration_middleware(Registration_Middleware $middleware): self { |
|
| 181 | + if ($this->registration === null) { |
|
| 182 | 182 | throw App_Initialization_Exception::requires_registration_service(); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // Set the loader to the registration service, if defined. |
| 186 | - if ( ! is_null( $this->loader ) ) { |
|
| 187 | - $this->registration->set_loader( $this->loader ); |
|
| 186 | + if ( ! is_null($this->loader)) { |
|
| 187 | + $this->registration->set_loader($this->loader); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - $this->registration->push_middleware( $middleware ); |
|
| 190 | + $this->registration->push_middleware($middleware); |
|
| 191 | 191 | |
| 192 | 192 | return $this; |
| 193 | 193 | } |
@@ -200,23 +200,23 @@ discard block |
||
| 200 | 200 | * @throws App_Initialization_Exception Code 1 If DI container not registered |
| 201 | 201 | * @throws App_Initialization_Exception Code 9 If class doesn't create as middleware. |
| 202 | 202 | */ |
| 203 | - public function construct_registration_middleware( string $class_name ): self { |
|
| 204 | - if ( self::$container === null ) { |
|
| 203 | + public function construct_registration_middleware(string $class_name): self { |
|
| 204 | + if (self::$container === null) { |
|
| 205 | 205 | throw App_Initialization_Exception::requires_di_container(); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | // Add to stack if finalise has not been run. |
| 209 | - if ( false === self::$booted ) { |
|
| 209 | + if (false === self::$booted) { |
|
| 210 | 210 | $this->middleware_class_names[] = $class_name; |
| 211 | 211 | return $this; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - $middleware = self::$container->create( $class_name ); |
|
| 215 | - if ( ! is_object( $middleware ) || ! is_a( $middleware, Registration_Middleware::class ) ) { |
|
| 216 | - throw App_Initialization_Exception::invalid_registration_middleware_instance( $class_name ); |
|
| 214 | + $middleware = self::$container->create($class_name); |
|
| 215 | + if ( ! is_object($middleware) || ! is_a($middleware, Registration_Middleware::class)) { |
|
| 216 | + throw App_Initialization_Exception::invalid_registration_middleware_instance($class_name); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - return $this->registration_middleware( $middleware ); |
|
| 219 | + return $this->registration_middleware($middleware); |
|
| 220 | 220 | |
| 221 | 221 | } |
| 222 | 222 | |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | * @return self |
| 228 | 228 | * @throws App_Initialization_Exception Code 3 |
| 229 | 229 | */ |
| 230 | - public function registration_classes( array $class_list ): self { |
|
| 231 | - if ( $this->registration === null ) { |
|
| 230 | + public function registration_classes(array $class_list): self { |
|
| 231 | + if ($this->registration === null) { |
|
| 232 | 232 | throw App_Initialization_Exception::requires_registration_service(); |
| 233 | 233 | } |
| 234 | - $this->registration->set_classes( $class_list ); |
|
| 234 | + $this->registration->set_classes($class_list); |
|
| 235 | 235 | return $this; |
| 236 | 236 | } |
| 237 | 237 | |
@@ -243,15 +243,15 @@ discard block |
||
| 243 | 243 | public function boot(): self { |
| 244 | 244 | |
| 245 | 245 | // Validate. |
| 246 | - $validate = new App_Validation( $this ); |
|
| 247 | - if ( $validate->validate() === false || $this->registration === null ) { |
|
| 246 | + $validate = new App_Validation($this); |
|
| 247 | + if ($validate->validate() === false || $this->registration === null) { |
|
| 248 | 248 | throw App_Initialization_Exception::failed_boot_validation( |
| 249 | 249 | $validate->errors |
| 250 | 250 | ); |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | // Process registration |
| 254 | - $this->registration->set_container( self::$container ); |
|
| 254 | + $this->registration->set_container(self::$container); |
|
| 255 | 255 | |
| 256 | 256 | // Run the final process, where all are loaded in via |
| 257 | 257 | $this->finalise(); |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | Inject_DI_Container::class, |
| 294 | 294 | array( |
| 295 | 295 | 'call' => array( |
| 296 | - array( 'set_di_container', array( self::$container ) ), |
|
| 296 | + array('set_di_container', array(self::$container)), |
|
| 297 | 297 | ), |
| 298 | 298 | ) |
| 299 | 299 | ); |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | Inject_Hook_Loader::class, |
| 304 | 304 | array( |
| 305 | 305 | 'call' => array( |
| 306 | - array( 'set_hook_loader', array( $this->loader ) ), |
|
| 306 | + array('set_hook_loader', array($this->loader)), |
|
| 307 | 307 | ), |
| 308 | 308 | ) |
| 309 | 309 | ); |
@@ -313,31 +313,31 @@ discard block |
||
| 313 | 313 | Inject_App_Config::class, |
| 314 | 314 | array( |
| 315 | 315 | 'call' => array( |
| 316 | - array( 'set_app_config', array( self::$app_config ) ), |
|
| 316 | + array('set_app_config', array(self::$app_config)), |
|
| 317 | 317 | ), |
| 318 | 318 | ) |
| 319 | 319 | ); |
| 320 | 320 | |
| 321 | 321 | // Process middleware classnames. |
| 322 | - foreach ( $this->middleware_class_names as $class_name ) { |
|
| 323 | - $middleware = self::$container->create( $class_name ); |
|
| 324 | - if ( ! is_object( $middleware ) || ! is_a( $middleware, Registration_Middleware::class ) ) { |
|
| 325 | - throw App_Initialization_Exception::invalid_registration_middleware_instance( $class_name ); |
|
| 322 | + foreach ($this->middleware_class_names as $class_name) { |
|
| 323 | + $middleware = self::$container->create($class_name); |
|
| 324 | + if ( ! is_object($middleware) || ! is_a($middleware, Registration_Middleware::class)) { |
|
| 325 | + throw App_Initialization_Exception::invalid_registration_middleware_instance($class_name); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - $this->registration_middleware( $middleware ); |
|
| 328 | + $this->registration_middleware($middleware); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /** @hook{string, App_Config, Loader, DI_Container} */ |
| 332 | - do_action( Hooks::APP_INIT_PRE_BOOT, self::$app_config, $this->loader, self::$container ); // phpcs:disable WordPress.NamingConventions.ValidHookName.* |
|
| 332 | + do_action(Hooks::APP_INIT_PRE_BOOT, self::$app_config, $this->loader, self::$container); // phpcs:disable WordPress.NamingConventions.ValidHookName.* |
|
| 333 | 333 | |
| 334 | 334 | // Initialise on init |
| 335 | 335 | add_action( |
| 336 | 336 | 'init', |
| 337 | - function () { |
|
| 338 | - do_action( Hooks::APP_INIT_PRE_REGISTRATION, self::$app_config, $this->loader, self::$container ); |
|
| 337 | + function() { |
|
| 338 | + do_action(Hooks::APP_INIT_PRE_REGISTRATION, self::$app_config, $this->loader, self::$container); |
|
| 339 | 339 | $this->registration->process(); |
| 340 | - do_action( Hooks::APP_INIT_POST_REGISTRATION, self::$app_config, $this->loader, self::$container ); |
|
| 340 | + do_action(Hooks::APP_INIT_POST_REGISTRATION, self::$app_config, $this->loader, self::$container); |
|
| 341 | 341 | $this->loader->register_hooks(); // @phpstan-ignore-line, if loader is not defined, exception will be thrown above |
| 342 | 342 | }, |
| 343 | 343 | 1 |
@@ -356,11 +356,11 @@ discard block |
||
| 356 | 356 | * @return object|null |
| 357 | 357 | * @throws App_Initialization_Exception Code 4 |
| 358 | 358 | */ |
| 359 | - public static function make( string $class, array $args = array() ) { |
|
| 360 | - if ( self::$booted === false ) { |
|
| 361 | - throw App_Initialization_Exception::app_not_initialized( DI_Container::class ); |
|
| 359 | + public static function make(string $class, array $args = array()) { |
|
| 360 | + if (self::$booted === false) { |
|
| 361 | + throw App_Initialization_Exception::app_not_initialized(DI_Container::class); |
|
| 362 | 362 | } |
| 363 | - return self::$container->create( $class, $args ); |
|
| 363 | + return self::$container->create($class, $args); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | /** |
@@ -371,11 +371,11 @@ discard block |
||
| 371 | 371 | * @return mixed |
| 372 | 372 | * @throws App_Initialization_Exception Code 4 |
| 373 | 373 | */ |
| 374 | - public static function config( string $key, string ...$child ) { |
|
| 375 | - if ( self::$booted === false ) { |
|
| 376 | - throw App_Initialization_Exception::app_not_initialized( App_Config::class ); |
|
| 374 | + public static function config(string $key, string ...$child) { |
|
| 375 | + if (self::$booted === false) { |
|
| 376 | + throw App_Initialization_Exception::app_not_initialized(App_Config::class); |
|
| 377 | 377 | } |
| 378 | - return self::$app_config->{$key}( ...$child ); |
|
| 378 | + return self::$app_config->{$key}(...$child); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -385,11 +385,11 @@ discard block |
||
| 385 | 385 | * @throws App_Initialization_Exception Code 4 |
| 386 | 386 | */ |
| 387 | 387 | public static function view(): ?View { |
| 388 | - if ( self::$booted === false ) { |
|
| 389 | - throw App_Initialization_Exception::app_not_initialized( View::class ); |
|
| 388 | + if (self::$booted === false) { |
|
| 389 | + throw App_Initialization_Exception::app_not_initialized(View::class); |
|
| 390 | 390 | } |
| 391 | 391 | /** @var ?View */ |
| 392 | - return self::$container->create( View::class ); |
|
| 392 | + return self::$container->create(View::class); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** @return array{container:DI_Container,app_config:App_Config,booted:bool} */ |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | * @return bool |
| 408 | 408 | */ |
| 409 | 409 | public function has_app_config(): bool { |
| 410 | - return is_a( self::$app_config, App_Config::class ); |
|
| 410 | + return is_a(self::$app_config, App_Config::class); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | * @throws App_Initialization_Exception (Code 1) |
| 418 | 418 | */ |
| 419 | 419 | public function get_container(): DI_Container { |
| 420 | - if ( self::$container === null ) { |
|
| 420 | + if (self::$container === null) { |
|
| 421 | 421 | // Throw container not set. |
| 422 | 422 | throw App_Initialization_Exception::requires_di_container(); |
| 423 | 423 | } |
@@ -34,12 +34,12 @@ |
||
| 34 | 34 | * @param array<int, mixed> $params |
| 35 | 35 | * @return mixed |
| 36 | 36 | */ |
| 37 | - public static function __callStatic( $method, $params ) { |
|
| 38 | - if ( ! self::$config_cache ) { |
|
| 37 | + public static function __callStatic($method, $params) { |
|
| 38 | + if ( ! self::$config_cache) { |
|
| 39 | 39 | /** @phpstan-ignore-next-line */ |
| 40 | - self::$config_cache = App::make( App_Config::class ); |
|
| 40 | + self::$config_cache = App::make(App_Config::class); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - return self::$config_cache->{$method}( ...$params ); |
|
| 43 | + return self::$config_cache->{$method}(...$params); |
|
| 44 | 44 | } |
| 45 | 45 | } |
@@ -28,4 +28,4 @@ |
||
| 28 | 28 | use Exception; |
| 29 | 29 | use Psr\Container\NotFoundExceptionInterface; |
| 30 | 30 | |
| 31 | -class DI_Container_Exception extends Exception implements NotFoundExceptionInterface{} |
|
| 31 | +class DI_Container_Exception extends Exception implements NotFoundExceptionInterface {} |
|
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public static function requires_di_container(): App_Initialization_Exception { |
| 38 | 38 | $message = 'The Application must be populated with a DI_Container before booting.'; |
| 39 | - return new App_Initialization_Exception( $message, 1 ); |
|
| 39 | + return new App_Initialization_Exception($message, 1); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public static function di_container_exists(): App_Initialization_Exception { |
| 48 | 48 | $message = 'App already contains a DI Container, can not redeclare.'; |
| 49 | - return new App_Initialization_Exception( $message, 2 ); |
|
| 49 | + return new App_Initialization_Exception($message, 2); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | public static function requires_registration_service(): App_Initialization_Exception { |
| 58 | 58 | $message = 'App has not defined Registration Service, this must be set before use.'; |
| 59 | - return new App_Initialization_Exception( $message, 3 ); |
|
| 59 | + return new App_Initialization_Exception($message, 3); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | * @param string $service The service which has been called without initialising the app. |
| 66 | 66 | * @return App_Initialization_Exception |
| 67 | 67 | */ |
| 68 | - public static function app_not_initialized( string $service ): App_Initialization_Exception { |
|
| 68 | + public static function app_not_initialized(string $service): App_Initialization_Exception { |
|
| 69 | 69 | $message = "App must be initialised before calling {$service}"; |
| 70 | - return new App_Initialization_Exception( $message, 4 ); |
|
| 70 | + return new App_Initialization_Exception($message, 4); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | public static function app_config_exists(): App_Initialization_Exception { |
| 79 | 79 | $message = 'Can not redeclare App_Config as its already set to the application'; |
| 80 | - return new App_Initialization_Exception( $message, 5 ); |
|
| 80 | + return new App_Initialization_Exception($message, 5); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public static function registration_exists(): App_Initialization_Exception { |
| 89 | 89 | $message = 'Can not redeclare Registration_Service as its already set to the application'; |
| 90 | - return new App_Initialization_Exception( $message, 7 ); |
|
| 90 | + return new App_Initialization_Exception($message, 7); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -96,12 +96,12 @@ discard block |
||
| 96 | 96 | * @param array<int,string> $errors |
| 97 | 97 | * @return App_Initialization_Exception |
| 98 | 98 | */ |
| 99 | - public static function failed_boot_validation( array $errors ): App_Initialization_Exception { |
|
| 99 | + public static function failed_boot_validation(array $errors): App_Initialization_Exception { |
|
| 100 | 100 | $message = sprintf( |
| 101 | 101 | 'App failed boot validation : %s', |
| 102 | - join( ',', $errors ) |
|
| 102 | + join(',', $errors) |
|
| 103 | 103 | ); |
| 104 | - return new App_Initialization_Exception( $message, 6 ); |
|
| 104 | + return new App_Initialization_Exception($message, 6); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public static function loader_exists(): App_Initialization_Exception { |
| 113 | 113 | $message = 'Can not redeclare Loader as its already set to the application'; |
| 114 | - return new App_Initialization_Exception( $message, 8 ); |
|
| 114 | + return new App_Initialization_Exception($message, 8); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -120,12 +120,12 @@ discard block |
||
| 120 | 120 | * @param string $class |
| 121 | 121 | * @return App_Initialization_Exception |
| 122 | 122 | */ |
| 123 | - public static function invalid_registration_middleware_instance( string $class ): App_Initialization_Exception { |
|
| 123 | + public static function invalid_registration_middleware_instance(string $class): App_Initialization_Exception { |
|
| 124 | 124 | $message = sprintf( |
| 125 | 125 | '%s is not a valid instance of Registration_Middleware', |
| 126 | 126 | $class |
| 127 | 127 | ); |
| 128 | - return new App_Initialization_Exception( $message, 9 ); |
|
| 128 | + return new App_Initialization_Exception($message, 9); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | } |
@@ -33,5 +33,5 @@ |
||
| 33 | 33 | * @param App_Config $app_config |
| 34 | 34 | * @return void |
| 35 | 35 | */ |
| 36 | - public function set_app_config( App_Config $app_config ): void; |
|
| 36 | + public function set_app_config(App_Config $app_config): void; |
|
| 37 | 37 | } |
@@ -34,5 +34,5 @@ |
||
| 34 | 34 | * @param Hook_Loader $hook_loader |
| 35 | 35 | * @return void |
| 36 | 36 | */ |
| 37 | - public function set_hook_loader( Hook_Loader $hook_loader ): void; |
|
| 37 | + public function set_hook_loader(Hook_Loader $hook_loader): void; |
|
| 38 | 38 | } |
@@ -33,5 +33,5 @@ |
||
| 33 | 33 | * @param DI_Container $container |
| 34 | 34 | * @return void |
| 35 | 35 | */ |
| 36 | - public function set_di_container( DI_Container $container ): void; |
|
| 36 | + public function set_di_container(DI_Container $container): void; |
|
| 37 | 37 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param array<string, array<mixed>> $rule |
| 37 | 37 | * @return DI_Container |
| 38 | 38 | */ |
| 39 | - public function addRule( string $name, array $rule ): DI_Container; |
|
| 39 | + public function addRule(string $name, array $rule): DI_Container; |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Add multiple rules |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param array<string, array<mixed>> $rules |
| 45 | 45 | * @return DI_Container |
| 46 | 46 | */ |
| 47 | - public function addRules( array $rules ): DI_Container; |
|
| 47 | + public function addRules(array $rules): DI_Container; |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Create an instance of a class, with optional parameters. |
@@ -53,5 +53,5 @@ discard block |
||
| 53 | 53 | * @param array<mixed> $args |
| 54 | 54 | * @return object|null |
| 55 | 55 | */ |
| 56 | - public function create( string $name, array $args = array() ); |
|
| 56 | + public function create(string $name, array $args = array()); |
|
| 57 | 57 | } |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | * @param object $class |
| 34 | 34 | * @return object |
| 35 | 35 | */ |
| 36 | - public function process( $class ); |
|
| 36 | + public function process($class); |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Used to for any middleware setup before process is called |