@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @var array; |
51 | 51 | */ |
52 | - protected $dependencies = [ ]; |
|
52 | + protected $dependencies = []; |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Hold the handlers. |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @var array |
60 | 60 | */ |
61 | - protected $handlers = [ ]; |
|
61 | + protected $handlers = []; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Instantiate DependencyManager object. |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @throws InvalidArgumentException If no dependency handlers were |
74 | 74 | * specified. |
75 | 75 | */ |
76 | - public function __construct( ConfigInterface $config, $config_key = null ) { |
|
76 | + public function __construct(ConfigInterface $config, $config_key = null) { |
|
77 | 77 | $this->processConfig( |
78 | 78 | $config, |
79 | 79 | $config_key ?: self::KEY_DEPENDENCY_SUBTREE |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | * @since 0.1.0 |
89 | 89 | */ |
90 | 90 | protected function init_handlers() { |
91 | - $keys = [ self::KEY_SCRIPTS, self::KEY_STYLES ]; |
|
92 | - foreach ( $keys as $key ) { |
|
93 | - if ( $this->hasConfigKey( $key ) ) { |
|
94 | - $this->add_handler( $key ); |
|
91 | + $keys = [self::KEY_SCRIPTS, self::KEY_STYLES]; |
|
92 | + foreach ($keys as $key) { |
|
93 | + if ($this->hasConfigKey($key)) { |
|
94 | + $this->add_handler($key); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | } |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @param string $dependency The dependency type for which to add a handler. |
105 | 105 | */ |
106 | - protected function add_handler( $dependency ) { |
|
107 | - if ( $this->hasConfigKey( $dependency ) ) { |
|
108 | - $handler = $this->hasConfigKey( self::KEY_HANDLERS, $dependency ) |
|
109 | - ? $this->getConfigKey( self::KEY_HANDLERS, $dependency ) |
|
110 | - : $this->get_default_handler( $dependency ); |
|
111 | - if ( $handler ) { |
|
106 | + protected function add_handler($dependency) { |
|
107 | + if ($this->hasConfigKey($dependency)) { |
|
108 | + $handler = $this->hasConfigKey(self::KEY_HANDLERS, $dependency) |
|
109 | + ? $this->getConfigKey(self::KEY_HANDLERS, $dependency) |
|
110 | + : $this->get_default_handler($dependency); |
|
111 | + if ($handler) { |
|
112 | 112 | $this->handlers[] = $handler; |
113 | 113 | } |
114 | 114 | } |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * @param string $dependency The dependency that needs a handler. |
123 | 123 | * @return string|null Class name of the handler. Null if none. |
124 | 124 | */ |
125 | - protected function get_default_handler( $dependency ) { |
|
126 | - switch ( $dependency ) { |
|
125 | + protected function get_default_handler($dependency) { |
|
126 | + switch ($dependency) { |
|
127 | 127 | case self::KEY_STYLES: |
128 | 128 | return self::DEFAULT_STYLE_HANDLER; |
129 | 129 | case self::KEY_SCRIPTS: |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | * @since 0.1.0 |
140 | 140 | */ |
141 | 141 | protected function init_dependencies() { |
142 | - array_walk( $this->handlers, |
|
143 | - function ( $handler, $dependency_type ) use ( $config ) { |
|
144 | - if ( ! empty( $config[ $dependency_type ] ) ) { |
|
145 | - $this->dependencies[ $dependency_type ] = $config[ $dependency_type ]; |
|
142 | + array_walk($this->handlers, |
|
143 | + function($handler, $dependency_type) use ($config) { |
|
144 | + if ( ! empty($config[$dependency_type])) { |
|
145 | + $this->dependencies[$dependency_type] = $config[$dependency_type]; |
|
146 | 146 | } |
147 | 147 | } ); |
148 | 148 | } |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @param mixed $context Optional. The context to pass to the dependencies. |
156 | 156 | */ |
157 | - public function register( $context = null ) { |
|
158 | - array_walk( $this->dependencies, |
|
159 | - [ $this, 'register_dependency_type' ], $context ); |
|
157 | + public function register($context = null) { |
|
158 | + array_walk($this->dependencies, |
|
159 | + [$this, 'register_dependency_type'], $context); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @param mixed $context Optional. The context to pass to the dependencies. |
168 | 168 | */ |
169 | - public function enqueue( $context = null ) { |
|
170 | - array_walk( $this->dependencies, |
|
171 | - [ $this, 'enqueue_dependency_type' ], $context ); |
|
169 | + public function enqueue($context = null) { |
|
170 | + array_walk($this->dependencies, |
|
171 | + [$this, 'enqueue_dependency_type'], $context); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | * @param mixed $context Optional. The context to pass to the |
182 | 182 | * dependencies. |
183 | 183 | */ |
184 | - protected function enqueue_dependency_type( $dependencies, $dependency_type, $context = null ) { |
|
184 | + protected function enqueue_dependency_type($dependencies, $dependency_type, $context = null) { |
|
185 | 185 | $context['dependency_type'] = $dependency_type; |
186 | - array_walk( $dependencies, [ $this, 'enqueue_dependency' ], $context ); |
|
186 | + array_walk($dependencies, [$this, 'enqueue_dependency'], $context); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | * @param mixed $context Optional. The context to pass to the |
197 | 197 | * dependencies. |
198 | 198 | */ |
199 | - protected function register_dependency_type( $dependencies, $dependency_type, $context = null ) { |
|
199 | + protected function register_dependency_type($dependencies, $dependency_type, $context = null) { |
|
200 | 200 | $context['dependency_type'] = $dependency_type; |
201 | - array_walk( $dependencies, [ $this, 'register_dependency' ], $context ); |
|
201 | + array_walk($dependencies, [$this, 'register_dependency'], $context); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -212,16 +212,16 @@ discard block |
||
212 | 212 | * Contains the type of the dependency at key |
213 | 213 | * 'dependency_type'. |
214 | 214 | */ |
215 | - protected function register_dependency( $dependency, $dependency_key, $context ) { |
|
215 | + protected function register_dependency($dependency, $dependency_key, $context) { |
|
216 | 216 | /** @var \BrightNucleus\Contract\Registerable $handler */ |
217 | 217 | $handler = new $this->handlers[$context['dependency_type']]; |
218 | - $handler->register( $dependency ); |
|
219 | - \add_action( 'wp_enqueue_scripts', |
|
220 | - [ $this, 'enqueue' ] ); |
|
221 | - \add_action( 'admin_enqueue_scripts', |
|
222 | - [ $this, 'enqueue' ] ); |
|
223 | - if ( array_key_exists( 'localize', $dependency ) ) { |
|
224 | - $this->localize( $dependency, $context ); |
|
218 | + $handler->register($dependency); |
|
219 | + \add_action('wp_enqueue_scripts', |
|
220 | + [$this, 'enqueue']); |
|
221 | + \add_action('admin_enqueue_scripts', |
|
222 | + [$this, 'enqueue']); |
|
223 | + if (array_key_exists('localize', $dependency)) { |
|
224 | + $this->localize($dependency, $context); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
@@ -235,13 +235,13 @@ discard block |
||
235 | 235 | * Contains the type of the dependency at key |
236 | 236 | * 'dependency_type'. |
237 | 237 | */ |
238 | - protected function localize( $dependency, $context ) { |
|
238 | + protected function localize($dependency, $context) { |
|
239 | 239 | $localize = $dependency['localize']; |
240 | 240 | $data = $localize['data']; |
241 | - if ( is_callable( $data ) ) { |
|
242 | - $data = $data( $context ); |
|
241 | + if (is_callable($data)) { |
|
242 | + $data = $data($context); |
|
243 | 243 | } |
244 | - \wp_localize_script( $dependency['handle'], $localize['name'], $data ); |
|
244 | + \wp_localize_script($dependency['handle'], $localize['name'], $data); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -255,13 +255,13 @@ discard block |
||
255 | 255 | * Contains the type of the dependency at key |
256 | 256 | * 'dependency_type'. |
257 | 257 | */ |
258 | - protected function enqueue_dependency( $dependency, $dependency_key, $context ) { |
|
259 | - if ( ! $this->is_needed( $dependency, $context ) ) { |
|
258 | + protected function enqueue_dependency($dependency, $dependency_key, $context) { |
|
259 | + if ( ! $this->is_needed($dependency, $context)) { |
|
260 | 260 | return; |
261 | 261 | } |
262 | 262 | /** @var \BrightNucleus\Contract\Enqueueable $handler */ |
263 | 263 | $handler = new $this->handlers[$dependency_type]; |
264 | - $handler->enqueue( $dependency ); |
|
264 | + $handler->enqueue($dependency); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -275,15 +275,15 @@ discard block |
||
275 | 275 | * 'dependency_type'. |
276 | 276 | * @return bool Whether it is needed or not. |
277 | 277 | */ |
278 | - protected function is_needed( $dependency, $context ) { |
|
279 | - $is_needed = array_key_exists( 'is_needed', $dependency ) |
|
278 | + protected function is_needed($dependency, $context) { |
|
279 | + $is_needed = array_key_exists('is_needed', $dependency) |
|
280 | 280 | ? $dependency['is_needed'] |
281 | 281 | : null; |
282 | 282 | |
283 | - if ( null === $is_needed ) { |
|
283 | + if (null === $is_needed) { |
|
284 | 284 | return true; |
285 | 285 | } |
286 | 286 | |
287 | - return is_callable( $is_needed ) && $is_needed( $context ); |
|
287 | + return is_callable($is_needed) && $is_needed($context); |
|
288 | 288 | } |
289 | 289 | } |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * DependencyManagerInterface Interface. |
|
4 | - * |
|
5 | - * @package BrightNucleus\Dependency |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license GPL-2.0+ |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2015 Alain Schlesser, Bright NucleusInterface |
|
10 | - */ |
|
3 | + * DependencyManagerInterface Interface. |
|
4 | + * |
|
5 | + * @package BrightNucleus\Dependency |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license GPL-2.0+ |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2015 Alain Schlesser, Bright NucleusInterface |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | namespace BrightNucleus\Dependency; |
13 | 13 |