@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param array<string, 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() ): ?object; |
|
| 56 | + public function create(string $name, array $args = array()): ?object; |
|
| 57 | 57 | } |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | * @param T $class |
| 38 | 38 | * @return T |
| 39 | 39 | */ |
| 40 | - public function process( object $class ): object; |
|
| 40 | + public function process(object $class): object; |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Used to for any middleware setup before process is called |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | private array $data = array(); |
| 43 | 43 | |
| 44 | 44 | /** @param array<string, mixed> $data */ |
| 45 | - public function __construct( string $template, array $data = array() ) { |
|
| 45 | + public function __construct(string $template, array $data = array()) { |
|
| 46 | 46 | $this->template = $template; |
| 47 | 47 | $this->data = $data; |
| 48 | 48 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @param Dice $dice |
| 45 | 45 | */ |
| 46 | - public function __construct( Dice $dice ) { |
|
| 46 | + public function __construct(Dice $dice) { |
|
| 47 | 47 | $this->dice = $dice; |
| 48 | 48 | } |
| 49 | 49 | |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | * @param Dice $dice |
| 54 | 54 | * @return self |
| 55 | 55 | */ |
| 56 | - public static function withDice( Dice $dice ): self { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
| 57 | - return new PinkCrab_Dice( $dice ); |
|
| 56 | + public static function withDice(Dice $dice): self { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
| 57 | + return new PinkCrab_Dice($dice); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | * @param string $id Class name (fully namespaced.) |
| 65 | 65 | * @return object|null |
| 66 | 66 | */ |
| 67 | - public function get( string $id ): ?object { |
|
| 68 | - if ( ! $this->has( $id ) ) { |
|
| 69 | - throw new DI_Container_Exception( "{$id} not defined in container", 1 ); |
|
| 67 | + public function get(string $id): ?object { |
|
| 68 | + if ( ! $this->has($id)) { |
|
| 69 | + throw new DI_Container_Exception("{$id} not defined in container", 1); |
|
| 70 | 70 | } |
| 71 | - return $this->create( $id ); |
|
| 71 | + return $this->create($id); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -78,21 +78,21 @@ discard block |
||
| 78 | 78 | * @param string $id Class name (fully namespaced.) |
| 79 | 79 | * @return bool |
| 80 | 80 | */ |
| 81 | - public function has( string $id ): bool { |
|
| 82 | - $from_dice = $this->dice->getRule( $id ); |
|
| 81 | + public function has(string $id): bool { |
|
| 82 | + $from_dice = $this->dice->getRule($id); |
|
| 83 | 83 | // If set in global rules. |
| 84 | - if ( array_key_exists( 'substitutions', $from_dice ) |
|
| 85 | - && array_key_exists( $id, $from_dice['substitutions'] ) ) { |
|
| 84 | + if (array_key_exists('substitutions', $from_dice) |
|
| 85 | + && array_key_exists($id, $from_dice['substitutions'])) { |
|
| 86 | 86 | return true; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // If set with a replacement instance. |
| 90 | - if ( array_key_exists( 'instanceOf', $from_dice ) ) { |
|
| 90 | + if (array_key_exists('instanceOf', $from_dice)) { |
|
| 91 | 91 | return true; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | // Checks if the class exists |
| 95 | - return class_exists( $id ); |
|
| 95 | + return class_exists($id); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | * @param array<string, string|object|mixed[]> $rule |
| 103 | 103 | * @return PinkCrab_Dice |
| 104 | 104 | */ |
| 105 | - public function addRule( string $name, array $rule ): DI_Container { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
| 106 | - $this->dice = $this->dice->addRule( $name, $rule ); |
|
| 105 | + public function addRule(string $name, array $rule): DI_Container { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
| 106 | + $this->dice = $this->dice->addRule($name, $rule); |
|
| 107 | 107 | return $this; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | * @param array<string, mixed[]> $rules |
| 114 | 114 | * @return PinkCrab_Dice |
| 115 | 115 | */ |
| 116 | - public function addRules( array $rules ): DI_Container { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
| 117 | - $this->dice = $this->dice->addRules( apply_filters( Hooks::APP_INIT_SET_DI_RULES, $rules ) ); |
|
| 116 | + public function addRules(array $rules): DI_Container { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
| 117 | + $this->dice = $this->dice->addRules(apply_filters(Hooks::APP_INIT_SET_DI_RULES, $rules)); |
|
| 118 | 118 | return $this; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -125,8 +125,8 @@ discard block |
||
| 125 | 125 | * @param array<mixed> $args |
| 126 | 126 | * @return object|null |
| 127 | 127 | */ |
| 128 | - public function create( string $name, array $args = array() ): ?object { |
|
| 129 | - return $this->dice->create( $name, $args ); |
|
| 128 | + public function create(string $name, array $args = array()): ?object { |
|
| 129 | + return $this->dice->create($name, $args); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @param string $name |
| 136 | 136 | * @return array<mixed> |
| 137 | 137 | */ |
| 138 | - public function getRule( string $name ): ?array { |
|
| 139 | - return $this->dice->getRule( $name ); |
|
| 138 | + public function getRule(string $name): ?array { |
|
| 139 | + return $this->dice->getRule($name); |
|
| 140 | 140 | } |
| 141 | 141 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | protected DI_Container $di_container; |
| 55 | 55 | |
| 56 | - public function __construct( DI_Container $di_container ) { |
|
| 56 | + public function __construct(DI_Container $di_container) { |
|
| 57 | 57 | $this->di_container = $di_container; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | * @param Registration_Middleware $middleware |
| 64 | 64 | * @return self |
| 65 | 65 | */ |
| 66 | - public function push_middleware( Registration_Middleware $middleware ): self { |
|
| 67 | - $this->middleware[ \get_class( $middleware ) ] = $middleware; |
|
| 66 | + public function push_middleware(Registration_Middleware $middleware): self { |
|
| 67 | + $this->middleware[\get_class($middleware)] = $middleware; |
|
| 68 | 68 | return $this; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -73,15 +73,15 @@ discard block |
||
| 73 | 73 | * @template Class_Name of object |
| 74 | 74 | * @param class-string<Class_Name> $class |
| 75 | 75 | */ |
| 76 | - public function push_class( string $class ): self { |
|
| 76 | + public function push_class(string $class): self { |
|
| 77 | 77 | // If the class is already in the list, skip. |
| 78 | - if ( \in_array( $class, $this->class_list, true ) ) { |
|
| 78 | + if (\in_array($class, $this->class_list, true)) { |
|
| 79 | 79 | return $this; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // If $class is not a class, throw exception. |
| 83 | - if ( ! \class_exists( $class ) ) { |
|
| 84 | - throw Module_Manager_Exception::none_class_string_passed_to_registration( $class ); |
|
| 83 | + if ( ! \class_exists($class)) { |
|
| 84 | + throw Module_Manager_Exception::none_class_string_passed_to_registration($class); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $this->class_list[] = $class; |
@@ -95,25 +95,25 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function process(): void { |
| 97 | 97 | // Filter all classes, before processing. |
| 98 | - $class_list = apply_filters( Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list ); |
|
| 98 | + $class_list = apply_filters(Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list); |
|
| 99 | 99 | |
| 100 | 100 | // If class list is empty, skip. |
| 101 | - if ( empty( $class_list ) ) { |
|
| 101 | + if (empty($class_list)) { |
|
| 102 | 102 | return; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - foreach ( $this->middleware as $middleware ) { |
|
| 105 | + foreach ($this->middleware as $middleware) { |
|
| 106 | 106 | // Run middleware setup |
| 107 | 107 | $middleware->setup(); |
| 108 | 108 | |
| 109 | 109 | // Pass each class to the middleware. |
| 110 | - foreach ( $class_list as $class ) { |
|
| 110 | + foreach ($class_list as $class) { |
|
| 111 | 111 | // Construct class using container, |
| 112 | - $class_instance = $this->di_container->create( $class ); |
|
| 112 | + $class_instance = $this->di_container->create($class); |
|
| 113 | 113 | |
| 114 | 114 | // if valid object process via current middleware |
| 115 | - if ( is_object( $class_instance ) ) { |
|
| 116 | - $middleware->process( $class_instance ); |
|
| 115 | + if (is_object($class_instance)) { |
|
| 116 | + $middleware->process($class_instance); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @pram DI_Container $di_container |
| 52 | 52 | * @return void |
| 53 | 53 | */ |
| 54 | - public function pre_boot( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void { |
|
| 54 | + public function pre_boot(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void { |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @pram DI_Container $di_container |
| 64 | 64 | * @return void |
| 65 | 65 | */ |
| 66 | - public function pre_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void { |
|
| 66 | + public function pre_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void { |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -74,6 +74,6 @@ discard block |
||
| 74 | 74 | * @pram DI_Container $di_container |
| 75 | 75 | * @return void |
| 76 | 76 | */ |
| 77 | - public function post_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void { |
|
| 77 | + public function post_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void { |
|
| 78 | 78 | } |
| 79 | 79 | } |
@@ -41,10 +41,10 @@ |
||
| 41 | 41 | * @param object $class |
| 42 | 42 | * @return object |
| 43 | 43 | */ |
| 44 | - public function process( object $class ): object { |
|
| 45 | - if ( in_array( Hookable::class, class_implements( $class ) ?: array(), true ) ) { |
|
| 44 | + public function process(object $class): object { |
|
| 45 | + if (in_array(Hookable::class, class_implements($class) ?: array(), true)) { |
|
| 46 | 46 | /** @phpstan-ignore-next-line class must implement register for interface*/ |
| 47 | - $class->register( $this->loader ); |
|
| 47 | + $class->register($this->loader); |
|
| 48 | 48 | } |
| 49 | 49 | return $class; |
| 50 | 50 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @param DI_Container $di_container |
| 69 | 69 | */ |
| 70 | - public function __construct( DI_Container $di_container, Registration_Service $registration_service ) { |
|
| 70 | + public function __construct(DI_Container $di_container, Registration_Service $registration_service) { |
|
| 71 | 71 | $this->di_container = $di_container; |
| 72 | 72 | |
| 73 | 73 | // Create the registration service. |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | * @param ?callable(Module, ?Registration_Middleware):Module $config |
| 83 | 83 | * @return void |
| 84 | 84 | */ |
| 85 | - public function push_module( string $module_name, ?callable $config = null ): void { |
|
| 86 | - $this->modules[] = array( $module_name, $config ); |
|
| 85 | + public function push_module(string $module_name, ?callable $config = null): void { |
|
| 86 | + $this->modules[] = array($module_name, $config); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * |
| 92 | 92 | * @param class-string $class |
| 93 | 93 | */ |
| 94 | - public function register_class( string $class ): void { |
|
| 95 | - $this->registration_service->push_class( $class ); |
|
| 94 | + public function register_class(string $class): void { |
|
| 95 | + $this->registration_service->push_class($class); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -104,26 +104,26 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public function register_modules(): void { |
| 106 | 106 | // Allow for additional apps to hook into the Module Manager. |
| 107 | - do_action( Hooks::MODULE_MANAGER, $this ); |
|
| 107 | + do_action(Hooks::MODULE_MANAGER, $this); |
|
| 108 | 108 | |
| 109 | - foreach ( $this->modules as list($module_name, $config) ) { |
|
| 109 | + foreach ($this->modules as list($module_name, $config)) { |
|
| 110 | 110 | // Create the instance. |
| 111 | - $module = $this->create_module( $module_name ); |
|
| 111 | + $module = $this->create_module($module_name); |
|
| 112 | 112 | |
| 113 | 113 | // Create the middleware. |
| 114 | - $middleware = $this->create_middleware( $module ); |
|
| 114 | + $middleware = $this->create_middleware($module); |
|
| 115 | 115 | |
| 116 | 116 | // If a config is provided, call it. |
| 117 | - if ( ! is_null( $config ) ) { |
|
| 118 | - $module = $config( $module, $middleware ); |
|
| 117 | + if ( ! is_null($config)) { |
|
| 118 | + $module = $config($module, $middleware); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // Add to the modules and register all hooks. |
| 122 | - $this->register_hooks( $module ); |
|
| 122 | + $this->register_hooks($module); |
|
| 123 | 123 | |
| 124 | 124 | // Add to the middleware, if provided. |
| 125 | - if ( ! is_null( $middleware ) ) { |
|
| 126 | - $this->registration_service->push_middleware( $middleware ); |
|
| 125 | + if ( ! is_null($middleware)) { |
|
| 126 | + $this->registration_service->push_middleware($middleware); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | } |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | * @param class-string<Module> $module |
| 135 | 135 | * @return Module |
| 136 | 136 | */ |
| 137 | - private function create_module( string $module ): Module { |
|
| 138 | - $instance = $this->di_container->create( $module ); |
|
| 137 | + private function create_module(string $module): Module { |
|
| 138 | + $instance = $this->di_container->create($module); |
|
| 139 | 139 | |
| 140 | 140 | // If not an object or not an instance of the module interface, throw. |
| 141 | - if ( ! is_object( $instance ) |
|
| 142 | - || ! is_a( $instance, Module::class, true ) |
|
| 141 | + if ( ! is_object($instance) |
|
| 142 | + || ! is_a($instance, Module::class, true) |
|
| 143 | 143 | ) { |
| 144 | - throw Module_Manager_Exception::invalid_module_class_name( $module ); |
|
| 144 | + throw Module_Manager_Exception::invalid_module_class_name($module); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | return $instance; |
@@ -153,27 +153,27 @@ discard block |
||
| 153 | 153 | * @param Module $module |
| 154 | 154 | * @return Registration_Middleware|null |
| 155 | 155 | */ |
| 156 | - private function create_middleware( Module $module ): ?Registration_Middleware { |
|
| 156 | + private function create_middleware(Module $module): ?Registration_Middleware { |
|
| 157 | 157 | $middleware = $module->get_middleware(); |
| 158 | 158 | |
| 159 | 159 | // If no middleware is provided, return null. |
| 160 | - if ( is_null( $middleware ) ) { |
|
| 160 | + if (is_null($middleware)) { |
|
| 161 | 161 | return null; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // If not an object or not an instance of the module interface, throw. |
| 165 | - if ( ! is_a( $middleware, Registration_Middleware::class, true ) ) { |
|
| 166 | - throw Module_Manager_Exception::invalid_registration_middleware( $middleware ); |
|
| 165 | + if ( ! is_a($middleware, Registration_Middleware::class, true)) { |
|
| 166 | + throw Module_Manager_Exception::invalid_registration_middleware($middleware); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // Create the middleware. |
| 170 | - $middleware = $this->di_container->create( $middleware ); |
|
| 170 | + $middleware = $this->di_container->create($middleware); |
|
| 171 | 171 | |
| 172 | 172 | // If the middleware is not an object, throw. |
| 173 | - if ( ! is_object( $middleware ) |
|
| 174 | - || ! is_a( $middleware, Registration_Middleware::class, true ) |
|
| 173 | + if ( ! is_object($middleware) |
|
| 174 | + || ! is_a($middleware, Registration_Middleware::class, true) |
|
| 175 | 175 | ) { |
| 176 | - throw Module_Manager_Exception::failed_to_create_registration_middleware( $middleware ); |
|
| 176 | + throw Module_Manager_Exception::failed_to_create_registration_middleware($middleware); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | return $middleware; |
@@ -185,10 +185,10 @@ discard block |
||
| 185 | 185 | * @param Module $module |
| 186 | 186 | * @return void |
| 187 | 187 | */ |
| 188 | - private function register_hooks( Module $module ): void { |
|
| 189 | - add_action( Hooks::APP_INIT_PRE_BOOT, array( $module, 'pre_boot' ), 10, 3 ); |
|
| 190 | - add_action( Hooks::APP_INIT_PRE_REGISTRATION, array( $module, 'pre_register' ), 10, 3 ); |
|
| 191 | - add_action( Hooks::APP_INIT_POST_REGISTRATION, array( $module, 'post_register' ), 10, 3 ); |
|
| 188 | + private function register_hooks(Module $module): void { |
|
| 189 | + add_action(Hooks::APP_INIT_PRE_BOOT, array($module, 'pre_boot'), 10, 3); |
|
| 190 | + add_action(Hooks::APP_INIT_PRE_REGISTRATION, array($module, 'pre_register'), 10, 3); |
|
| 191 | + add_action(Hooks::APP_INIT_POST_REGISTRATION, array($module, 'post_register'), 10, 3); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | $this->module_manager->register_modules(); // @phpstan-ignore-line, already verified if not null |
| 363 | 363 | |
| 364 | 364 | /** |
| 365 | - * @hook{string, App_Config, Loader, DI_Container} |
|
| 365 | + * @hook{string, App_Config, Loader, DI_Container} |
|
| 366 | 366 | */ |
| 367 | 367 | do_action( Hooks::APP_INIT_PRE_BOOT, self::$app_config, $this->loader, self::$container ); // phpcs:disable WordPress.NamingConventions.ValidHookName.* |
| 368 | 368 | |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | throw App_Initialization_Exception::app_not_initialized( View::class ); |
| 425 | 425 | } |
| 426 | 426 | /** |
| 427 | - * @var ?View |
|
| 427 | + * @var ?View |
|
| 428 | 428 | */ |
| 429 | 429 | return self::$container->create( View::class ); // @phpstan-ignore-line, already verified if not null |
| 430 | 430 | } |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | * base_path:string, |
| 441 | 441 | * view_path:?string |
| 442 | 442 | * } |
| 443 | - */ |
|
| 443 | + */ |
|
| 444 | 444 | public function __debugInfo(): array { |
| 445 | 445 | return array( |
| 446 | 446 | 'container' => self::$container, |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @param string $base_path |
| 108 | 108 | */ |
| 109 | - public function __construct( string $base_path ) { |
|
| 109 | + public function __construct(string $base_path) { |
|
| 110 | 110 | $this->base_path = $base_path; |
| 111 | 111 | |
| 112 | 112 | // Assume the view path. |
| 113 | - $this->view_path = rtrim( $this->base_path, '/\\' ) . \DIRECTORY_SEPARATOR . 'views'; |
|
| 113 | + $this->view_path = rtrim($this->base_path, '/\\') . \DIRECTORY_SEPARATOR . 'views'; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @param string $view_path |
| 120 | 120 | * @return self |
| 121 | 121 | */ |
| 122 | - public function set_view_path( string $view_path ): self { |
|
| 122 | + public function set_view_path(string $view_path): self { |
|
| 123 | 123 | $this->view_path = $view_path; |
| 124 | 124 | return $this; |
| 125 | 125 | } |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | * @return self |
| 132 | 132 | * @throws App_Initialization_Exception Code 2 |
| 133 | 133 | */ |
| 134 | - public function set_container( DI_Container $container ): self { |
|
| 135 | - if ( self::$container !== null ) { |
|
| 134 | + public function set_container(DI_Container $container): self { |
|
| 135 | + if (self::$container !== null) { |
|
| 136 | 136 | throw App_Initialization_Exception::di_container_exists(); |
| 137 | 137 | } |
| 138 | 138 | |
@@ -157,28 +157,28 @@ discard block |
||
| 157 | 157 | * @return self |
| 158 | 158 | * @throws App_Initialization_Exception Code 5 |
| 159 | 159 | */ |
| 160 | - public function set_app_config( array $settings ): self { |
|
| 161 | - if ( self::$app_config !== null ) { |
|
| 160 | + public function set_app_config(array $settings): self { |
|
| 161 | + if (self::$app_config !== null) { |
|
| 162 | 162 | throw App_Initialization_Exception::app_config_exists(); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Run through the filter to allow for config changes. |
| 166 | - $settings = apply_filters( Hooks::APP_INIT_CONFIG_VALUES, $settings ); |
|
| 166 | + $settings = apply_filters(Hooks::APP_INIT_CONFIG_VALUES, $settings); |
|
| 167 | 167 | |
| 168 | 168 | // Ensure the base path and url are defined from app. |
| 169 | 169 | $settings['path'] = $settings['path'] ?? array(); |
| 170 | 170 | $settings['path']['plugin'] = $this->base_path; |
| 171 | - $settings['path']['view'] = $this->view_path ?? App_Config_Path_Helper::assume_view_path( $this->base_path ); |
|
| 171 | + $settings['path']['view'] = $this->view_path ?? App_Config_Path_Helper::assume_view_path($this->base_path); |
|
| 172 | 172 | |
| 173 | 173 | // Get the url from the base path. |
| 174 | 174 | $settings['url'] = $settings['url'] ?? array(); |
| 175 | - $settings['url']['plugin'] = App_Config_Path_Helper::assume_base_url( $this->base_path ); |
|
| 175 | + $settings['url']['plugin'] = App_Config_Path_Helper::assume_base_url($this->base_path); |
|
| 176 | 176 | $settings['url']['view'] = App_Config_Path_Helper::assume_view_url( |
| 177 | 177 | $this->base_path, |
| 178 | - $this->view_path ?? App_Config_Path_Helper::assume_view_path( $this->base_path ) |
|
| 178 | + $this->view_path ?? App_Config_Path_Helper::assume_view_path($this->base_path) |
|
| 179 | 179 | ); |
| 180 | 180 | |
| 181 | - self::$app_config = new App_Config( $settings ); |
|
| 181 | + self::$app_config = new App_Config($settings); |
|
| 182 | 182 | return $this; |
| 183 | 183 | } |
| 184 | 184 | |
@@ -189,8 +189,8 @@ discard block |
||
| 189 | 189 | * @return self |
| 190 | 190 | * @throws App_Initialization_Exception Code 10 |
| 191 | 191 | */ |
| 192 | - public function set_module_manager( Module_Manager $module_manager ): self { |
|
| 193 | - if ( $this->module_manager !== null ) { |
|
| 192 | + public function set_module_manager(Module_Manager $module_manager): self { |
|
| 193 | + if ($this->module_manager !== null) { |
|
| 194 | 194 | throw App_Initialization_Exception::module_manager_exists(); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -204,8 +204,8 @@ discard block |
||
| 204 | 204 | * @param \PinkCrab\Loader\Hook_Loader $loader |
| 205 | 205 | * @return self |
| 206 | 206 | */ |
| 207 | - public function set_loader( Hook_Loader $loader ): self { |
|
| 208 | - if ( $this->loader !== null ) { |
|
| 207 | + public function set_loader(Hook_Loader $loader): self { |
|
| 208 | + if ($this->loader !== null) { |
|
| 209 | 209 | throw App_Initialization_Exception::loader_exists(); |
| 210 | 210 | } |
| 211 | 211 | $this->loader = $loader; |
@@ -220,11 +220,11 @@ discard block |
||
| 220 | 220 | * @return self |
| 221 | 221 | * @throws App_Initialization_Exception Code 1 |
| 222 | 222 | */ |
| 223 | - public function container_config( callable $callback ): self { |
|
| 224 | - if ( self::$container === null ) { |
|
| 223 | + public function container_config(callable $callback): self { |
|
| 224 | + if (self::$container === null) { |
|
| 225 | 225 | throw App_Initialization_Exception::requires_di_container(); |
| 226 | 226 | } |
| 227 | - $callback( self::$container ); |
|
| 227 | + $callback(self::$container); |
|
| 228 | 228 | return $this; |
| 229 | 229 | } |
| 230 | 230 | |
@@ -235,13 +235,13 @@ discard block |
||
| 235 | 235 | * @return self |
| 236 | 236 | * @throws App_Initialization_Exception Code 3 |
| 237 | 237 | */ |
| 238 | - public function registration_classes( array $class_list ): self { |
|
| 239 | - if ( $this->module_manager === null ) { |
|
| 238 | + public function registration_classes(array $class_list): self { |
|
| 239 | + if ($this->module_manager === null) { |
|
| 240 | 240 | throw App_Initialization_Exception::requires_module_manager(); |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - foreach ( $class_list as $class ) { |
|
| 244 | - $this->module_manager->register_class( $class ); |
|
| 243 | + foreach ($class_list as $class) { |
|
| 244 | + $this->module_manager->register_class($class); |
|
| 245 | 245 | } |
| 246 | 246 | return $this; |
| 247 | 247 | } |
@@ -256,17 +256,17 @@ discard block |
||
| 256 | 256 | * @throws App_Initialization_Exception Code 1 If DI container not registered |
| 257 | 257 | * @throws App_Initialization_Exception Code 3 If module manager not defined. |
| 258 | 258 | */ |
| 259 | - public function module( string $module, ?callable $callback = null ): self { |
|
| 259 | + public function module(string $module, ?callable $callback = null): self { |
|
| 260 | 260 | // Check if module manager exists. |
| 261 | - if ( $this->module_manager === null ) { |
|
| 261 | + if ($this->module_manager === null) { |
|
| 262 | 262 | throw App_Initialization_Exception::requires_module_manager(); |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if ( self::$container === null ) { |
|
| 265 | + if (self::$container === null) { |
|
| 266 | 266 | throw App_Initialization_Exception::requires_di_container(); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - $this->module_manager->push_module( $module, $callback ); |
|
| 269 | + $this->module_manager->push_module($module, $callback); |
|
| 270 | 270 | |
| 271 | 271 | return $this; |
| 272 | 272 | } |
@@ -280,8 +280,8 @@ discard block |
||
| 280 | 280 | public function boot(): self { |
| 281 | 281 | |
| 282 | 282 | // Validate. |
| 283 | - $validate = new App_Validation( $this ); |
|
| 284 | - if ( $validate->validate() === false ) { |
|
| 283 | + $validate = new App_Validation($this); |
|
| 284 | + if ($validate->validate() === false) { |
|
| 285 | 285 | throw App_Initialization_Exception::failed_boot_validation( |
| 286 | 286 | $validate->errors |
| 287 | 287 | ); |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | Inject_Hook_Loader::class, |
| 334 | 334 | array( |
| 335 | 335 | 'call' => array( |
| 336 | - array( 'set_hook_loader', array( $this->loader ) ), |
|
| 336 | + array('set_hook_loader', array($this->loader)), |
|
| 337 | 337 | ), |
| 338 | 338 | ) |
| 339 | 339 | ); |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | Inject_App_Config::class, |
| 344 | 344 | array( |
| 345 | 345 | 'call' => array( |
| 346 | - array( 'set_app_config', array( self::$app_config ) ), |
|
| 346 | + array('set_app_config', array(self::$app_config)), |
|
| 347 | 347 | ), |
| 348 | 348 | ) |
| 349 | 349 | ); |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | Inject_DI_Container::class, |
| 354 | 354 | array( |
| 355 | 355 | 'call' => array( |
| 356 | - array( 'set_di_container', array( self::$container ) ), |
|
| 356 | + array('set_di_container', array(self::$container)), |
|
| 357 | 357 | ), |
| 358 | 358 | ) |
| 359 | 359 | ); |
@@ -364,15 +364,15 @@ discard block |
||
| 364 | 364 | /** |
| 365 | 365 | * @hook{string, App_Config, Loader, DI_Container} |
| 366 | 366 | */ |
| 367 | - do_action( Hooks::APP_INIT_PRE_BOOT, self::$app_config, $this->loader, self::$container ); // phpcs:disable WordPress.NamingConventions.ValidHookName.* |
|
| 367 | + do_action(Hooks::APP_INIT_PRE_BOOT, self::$app_config, $this->loader, self::$container); // phpcs:disable WordPress.NamingConventions.ValidHookName.* |
|
| 368 | 368 | |
| 369 | 369 | // Initialise on init |
| 370 | 370 | add_action( |
| 371 | 371 | 'init', |
| 372 | - function () { |
|
| 373 | - do_action( Hooks::APP_INIT_PRE_REGISTRATION, self::$app_config, $this->loader, self::$container ); |
|
| 372 | + function() { |
|
| 373 | + do_action(Hooks::APP_INIT_PRE_REGISTRATION, self::$app_config, $this->loader, self::$container); |
|
| 374 | 374 | $this->module_manager->process_middleware(); // @phpstan-ignore-line, already verified if not null |
| 375 | - do_action( Hooks::APP_INIT_POST_REGISTRATION, self::$app_config, $this->loader, self::$container ); |
|
| 375 | + do_action(Hooks::APP_INIT_POST_REGISTRATION, self::$app_config, $this->loader, self::$container); |
|
| 376 | 376 | $this->loader->register_hooks(); // @phpstan-ignore-line, if loader is not defined, exception will be thrown above |
| 377 | 377 | }, |
| 378 | 378 | 1 |
@@ -391,11 +391,11 @@ discard block |
||
| 391 | 391 | * @return object|null |
| 392 | 392 | * @throws App_Initialization_Exception Code 4 |
| 393 | 393 | */ |
| 394 | - public static function make( string $class, array $args = array() ): ?object { |
|
| 395 | - if ( self::$booted === false ) { |
|
| 396 | - throw App_Initialization_Exception::app_not_initialized( DI_Container::class ); |
|
| 394 | + public static function make(string $class, array $args = array()): ?object { |
|
| 395 | + if (self::$booted === false) { |
|
| 396 | + throw App_Initialization_Exception::app_not_initialized(DI_Container::class); |
|
| 397 | 397 | } |
| 398 | - return self::$container->create( $class, $args ); // @phpstan-ignore-line, already verified if not null |
|
| 398 | + return self::$container->create($class, $args); // @phpstan-ignore-line, already verified if not null |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | /** |
@@ -406,11 +406,11 @@ discard block |
||
| 406 | 406 | * @return mixed |
| 407 | 407 | * @throws App_Initialization_Exception Code 4 |
| 408 | 408 | */ |
| 409 | - public static function config( string $key, string ...$child ) { |
|
| 410 | - if ( self::$booted === false ) { |
|
| 411 | - throw App_Initialization_Exception::app_not_initialized( App_Config::class ); |
|
| 409 | + public static function config(string $key, string ...$child) { |
|
| 410 | + if (self::$booted === false) { |
|
| 411 | + throw App_Initialization_Exception::app_not_initialized(App_Config::class); |
|
| 412 | 412 | } |
| 413 | - return self::$app_config->{$key}( ...$child ); |
|
| 413 | + return self::$app_config->{$key}(...$child); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
@@ -420,13 +420,13 @@ discard block |
||
| 420 | 420 | * @throws App_Initialization_Exception Code 4 |
| 421 | 421 | */ |
| 422 | 422 | public static function view(): ?View { |
| 423 | - if ( self::$booted === false ) { |
|
| 424 | - throw App_Initialization_Exception::app_not_initialized( View::class ); |
|
| 423 | + if (self::$booted === false) { |
|
| 424 | + throw App_Initialization_Exception::app_not_initialized(View::class); |
|
| 425 | 425 | } |
| 426 | 426 | /** |
| 427 | 427 | * @var ?View |
| 428 | 428 | */ |
| 429 | - return self::$container->create( View::class ); // @phpstan-ignore-line, already verified if not null |
|
| 429 | + return self::$container->create(View::class); // @phpstan-ignore-line, already verified if not null |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | * @return boolean |
| 459 | 459 | */ |
| 460 | 460 | public function has_app_config(): bool { |
| 461 | - return Object_Helper::is_a( self::$app_config, App_Config::class ); |
|
| 461 | + return Object_Helper::is_a(self::$app_config, App_Config::class); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | * @throws App_Initialization_Exception (Code 1) |
| 469 | 469 | */ |
| 470 | 470 | public function get_container(): DI_Container { |
| 471 | - if ( self::$container === null ) { |
|
| 471 | + if (self::$container === null) { |
|
| 472 | 472 | // Throw container not set. |
| 473 | 473 | throw App_Initialization_Exception::requires_di_container(); |
| 474 | 474 | } |