@@ -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 | /** |