@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * @param string $handle The handle to check |
43 | 43 | * @return bool Whether it is registered or not. |
44 | 44 | */ |
45 | - public function is_registered( $handle ) { |
|
46 | - return wp_style_is( $handle, 'registered' ); |
|
45 | + public function is_registered($handle) { |
|
46 | + return wp_style_is($handle, 'registered'); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @param string $handle The handle to check |
55 | 55 | * @return bool Whether it is enqueued or not. |
56 | 56 | */ |
57 | - public function is_enqueued( $handle ) { |
|
58 | - return wp_style_is( $handle, 'enqueued' ); |
|
57 | + public function is_enqueued($handle) { |
|
58 | + return wp_style_is($handle, 'enqueued'); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @var array; |
52 | 52 | */ |
53 | - protected $dependencies = [ ]; |
|
53 | + protected $dependencies = []; |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Hold the handlers. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @var DependencyHandlerInterface[] |
61 | 61 | */ |
62 | - protected $handlers = [ ]; |
|
62 | + protected $handlers = []; |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * Whether to enqueue immediately upon registration. |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | * @throws InvalidArgumentException If no dependency handlers were |
84 | 84 | * specified. |
85 | 85 | */ |
86 | - public function __construct( ConfigInterface $config, $enqueue = true ) { |
|
87 | - $this->processConfig( $config ); |
|
86 | + public function __construct(ConfigInterface $config, $enqueue = true) { |
|
87 | + $this->processConfig($config); |
|
88 | 88 | $this->enqueue_immediately = $enqueue; |
89 | 89 | $this->init_handlers(); |
90 | 90 | $this->init_dependencies(); |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | * @since 0.1.0 |
97 | 97 | */ |
98 | 98 | protected function init_handlers() { |
99 | - $keys = [ self::KEY_SCRIPTS, self::KEY_STYLES ]; |
|
100 | - foreach ( $keys as $key ) { |
|
101 | - if ( $this->hasConfigKey( $key ) ) { |
|
102 | - $this->add_handler( $key ); |
|
99 | + $keys = [self::KEY_SCRIPTS, self::KEY_STYLES]; |
|
100 | + foreach ($keys as $key) { |
|
101 | + if ($this->hasConfigKey($key)) { |
|
102 | + $this->add_handler($key); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | } |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @param string $dependency The dependency type for which to add a handler. |
113 | 113 | */ |
114 | - protected function add_handler( $dependency ) { |
|
115 | - if ( $this->hasConfigKey( $dependency ) ) { |
|
116 | - $handler = $this->hasConfigKey( self::KEY_HANDLERS, $dependency ) |
|
117 | - ? $this->getConfigKey( self::KEY_HANDLERS, $dependency ) |
|
118 | - : $this->get_default_handler( $dependency ); |
|
119 | - if ( $handler ) { |
|
120 | - $this->handlers[ $dependency ] = new $handler; |
|
114 | + protected function add_handler($dependency) { |
|
115 | + if ($this->hasConfigKey($dependency)) { |
|
116 | + $handler = $this->hasConfigKey(self::KEY_HANDLERS, $dependency) |
|
117 | + ? $this->getConfigKey(self::KEY_HANDLERS, $dependency) |
|
118 | + : $this->get_default_handler($dependency); |
|
119 | + if ($handler) { |
|
120 | + $this->handlers[$dependency] = new $handler; |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | } |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * @param string $dependency The dependency that needs a handler. |
131 | 131 | * @return string|null Class name of the handler. Null if none. |
132 | 132 | */ |
133 | - protected function get_default_handler( $dependency ) { |
|
134 | - switch ( $dependency ) { |
|
133 | + protected function get_default_handler($dependency) { |
|
134 | + switch ($dependency) { |
|
135 | 135 | case self::KEY_STYLES: |
136 | 136 | return self::DEFAULT_STYLE_HANDLER; |
137 | 137 | case self::KEY_SCRIPTS: |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | * @since 0.1.0 |
148 | 148 | */ |
149 | 149 | protected function init_dependencies() { |
150 | - array_walk( $this->handlers, |
|
151 | - function ( $handler, $dependency_type ) { |
|
152 | - if ( $this->hasConfigKey( $dependency_type ) ) { |
|
153 | - $this->dependencies[ $dependency_type ] = $this->init_dependency_type( $dependency_type ); |
|
150 | + array_walk($this->handlers, |
|
151 | + function($handler, $dependency_type) { |
|
152 | + if ($this->hasConfigKey($dependency_type)) { |
|
153 | + $this->dependencies[$dependency_type] = $this->init_dependency_type($dependency_type); |
|
154 | 154 | } |
155 | 155 | } ); |
156 | 156 | } |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | * @param string $type The type of dependency to initialize. |
164 | 164 | * @return array Array of dependency configurations. |
165 | 165 | */ |
166 | - protected function init_dependency_type( $type ) { |
|
167 | - $array = [ ]; |
|
168 | - $data = $this->getConfigKey( $type ); |
|
169 | - foreach ( $data as $dependency ) { |
|
170 | - $handle = array_key_exists( 'handle', |
|
171 | - $dependency ) ? $dependency['handle'] : ''; |
|
172 | - $array[ $handle ] = $dependency; |
|
166 | + protected function init_dependency_type($type) { |
|
167 | + $array = []; |
|
168 | + $data = $this->getConfigKey($type); |
|
169 | + foreach ($data as $dependency) { |
|
170 | + $handle = array_key_exists('handle', |
|
171 | + $dependency) ? $dependency['handle'] : ''; |
|
172 | + $array[$handle] = $dependency; |
|
173 | 173 | } |
174 | 174 | return $array; |
175 | 175 | } |
@@ -181,10 +181,10 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @param mixed $context Optional. The context to pass to the dependencies. |
183 | 183 | */ |
184 | - public function register( $context = null ) { |
|
185 | - $context = $this->validate_context( $context ); |
|
186 | - array_walk( $this->dependencies, |
|
187 | - [ $this, 'register_dependency_type' ], $context ); |
|
184 | + public function register($context = null) { |
|
185 | + $context = $this->validate_context($context); |
|
186 | + array_walk($this->dependencies, |
|
187 | + [$this, 'register_dependency_type'], $context); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | * @param mixed $context The context as passed in by WordPress. |
196 | 196 | * @return array Validated context. |
197 | 197 | */ |
198 | - protected function validate_context( $context ) { |
|
199 | - if ( is_string( $context ) ) { |
|
200 | - return [ 'wp_context' => $context ]; |
|
198 | + protected function validate_context($context) { |
|
199 | + if (is_string($context)) { |
|
200 | + return ['wp_context' => $context]; |
|
201 | 201 | } |
202 | 202 | return (array) $context; |
203 | 203 | } |
@@ -210,11 +210,11 @@ discard block |
||
210 | 210 | * @param mixed $context Optional. The context to pass to the |
211 | 211 | * dependencies. |
212 | 212 | */ |
213 | - public function enqueue( $context = null ) { |
|
214 | - $context = $this->validate_context( $context ); |
|
213 | + public function enqueue($context = null) { |
|
214 | + $context = $this->validate_context($context); |
|
215 | 215 | |
216 | - array_walk( $this->dependencies, |
|
217 | - [ $this, 'enqueue_dependency_type' ], $context ); |
|
216 | + array_walk($this->dependencies, |
|
217 | + [$this, 'enqueue_dependency_type'], $context); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -229,14 +229,14 @@ discard block |
||
229 | 229 | * outside of DependencyManager. Defaults to false. |
230 | 230 | * @return bool Returns whether the handle was found or not. |
231 | 231 | */ |
232 | - public function enqueue_handle( $handle, $context = null, $fallback = false ) { |
|
233 | - $handler = $this->handlers[ $context['dependency_type'] ]; |
|
234 | - if ( $handler->is_enqueued( $handle ) ) { |
|
232 | + public function enqueue_handle($handle, $context = null, $fallback = false) { |
|
233 | + $handler = $this->handlers[$context['dependency_type']]; |
|
234 | + if ($handler->is_enqueued($handle)) { |
|
235 | 235 | return true; |
236 | 236 | } |
237 | 237 | |
238 | - if ( ! $this->enqueue_internal_handle( $handle, $context ) ) { |
|
239 | - return $this->enqueue_fallback_handle( $handle ); |
|
238 | + if ( ! $this->enqueue_internal_handle($handle, $context)) { |
|
239 | + return $this->enqueue_fallback_handle($handle); |
|
240 | 240 | } |
241 | 241 | return true; |
242 | 242 | } |
@@ -252,11 +252,11 @@ discard block |
||
252 | 252 | * dependencies. |
253 | 253 | * @return bool Returns whether the handle was found or not. |
254 | 254 | */ |
255 | - protected function enqueue_internal_handle( $handle, $context = null ) { |
|
256 | - list( $dependency_type, $dependency ) = $this->get_dependency_array( $handle ); |
|
255 | + protected function enqueue_internal_handle($handle, $context = null) { |
|
256 | + list($dependency_type, $dependency) = $this->get_dependency_array($handle); |
|
257 | 257 | $context['dependency_type'] = $dependency_type; |
258 | 258 | |
259 | - if ( ! $dependency ) { |
|
259 | + if ( ! $dependency) { |
|
260 | 260 | return false; |
261 | 261 | } |
262 | 262 | |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | $context |
267 | 267 | ); |
268 | 268 | |
269 | - $this->maybe_localize( $dependency, $context ); |
|
270 | - $this->maybe_add_inline_script( $dependency, $context ); |
|
269 | + $this->maybe_localize($dependency, $context); |
|
270 | + $this->maybe_add_inline_script($dependency, $context); |
|
271 | 271 | |
272 | 272 | return true; |
273 | 273 | } |
@@ -281,14 +281,14 @@ discard block |
||
281 | 281 | * @return array Array containing the dependency key as well as the |
282 | 282 | * dependency array itself. |
283 | 283 | */ |
284 | - protected function get_dependency_array( $handle ) { |
|
285 | - foreach ( $this->dependencies as $type => $dependencies ) { |
|
286 | - if ( array_key_exists( $handle, $dependencies ) ) { |
|
287 | - return [ $type, $dependencies[ $handle ] ]; |
|
284 | + protected function get_dependency_array($handle) { |
|
285 | + foreach ($this->dependencies as $type => $dependencies) { |
|
286 | + if (array_key_exists($handle, $dependencies)) { |
|
287 | + return [$type, $dependencies[$handle]]; |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | // Handle not found, return an empty array. |
291 | - return [ '', null ]; |
|
291 | + return ['', null]; |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -303,19 +303,19 @@ discard block |
||
303 | 303 | * dependency at key |
304 | 304 | * 'dependency_type'. |
305 | 305 | */ |
306 | - protected function enqueue_dependency( $dependency, $dependency_key, $context = null ) { |
|
307 | - $handler = $this->handlers[ $context['dependency_type'] ]; |
|
308 | - $handle = array_key_exists( 'handle', $dependency ) ? $dependency['handle'] : ''; |
|
306 | + protected function enqueue_dependency($dependency, $dependency_key, $context = null) { |
|
307 | + $handler = $this->handlers[$context['dependency_type']]; |
|
308 | + $handle = array_key_exists('handle', $dependency) ? $dependency['handle'] : ''; |
|
309 | 309 | |
310 | - if ( $handle && $handler->is_enqueued( $handle ) ) { |
|
310 | + if ($handle && $handler->is_enqueued($handle)) { |
|
311 | 311 | return; |
312 | 312 | } |
313 | 313 | |
314 | - if ( ! $this->is_needed( $dependency, $context ) ) { |
|
314 | + if ( ! $this->is_needed($dependency, $context)) { |
|
315 | 315 | return; |
316 | 316 | } |
317 | 317 | |
318 | - $handler->enqueue( $dependency ); |
|
318 | + $handler->enqueue($dependency); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -329,16 +329,16 @@ discard block |
||
329 | 329 | * 'dependency_type'. |
330 | 330 | * @return bool Whether it is needed or not. |
331 | 331 | */ |
332 | - protected function is_needed( $dependency, $context ) { |
|
333 | - $is_needed = array_key_exists( 'is_needed', $dependency ) |
|
332 | + protected function is_needed($dependency, $context) { |
|
333 | + $is_needed = array_key_exists('is_needed', $dependency) |
|
334 | 334 | ? $dependency['is_needed'] |
335 | 335 | : null; |
336 | 336 | |
337 | - if ( null === $is_needed ) { |
|
337 | + if (null === $is_needed) { |
|
338 | 338 | return true; |
339 | 339 | } |
340 | 340 | |
341 | - return is_callable( $is_needed ) && $is_needed( $context ); |
|
341 | + return is_callable($is_needed) && $is_needed($context); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -351,21 +351,21 @@ discard block |
||
351 | 351 | * Contains the type of the dependency at key |
352 | 352 | * 'dependency_type'. |
353 | 353 | */ |
354 | - protected function maybe_localize( $dependency, $context ) { |
|
354 | + protected function maybe_localize($dependency, $context) { |
|
355 | 355 | static $already_localized = []; |
356 | - if ( ! array_key_exists( 'localize', $dependency ) |
|
357 | - || array_key_exists( $dependency['handle'], $already_localized ) ) { |
|
356 | + if ( ! array_key_exists('localize', $dependency) |
|
357 | + || array_key_exists($dependency['handle'], $already_localized)) { |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | 361 | $localize = $dependency['localize']; |
362 | 362 | $data = $localize['data']; |
363 | - if ( is_callable( $data ) ) { |
|
364 | - $data = $data( $context ); |
|
363 | + if (is_callable($data)) { |
|
364 | + $data = $data($context); |
|
365 | 365 | } |
366 | 366 | |
367 | - wp_localize_script( $dependency['handle'], $localize['name'], $data ); |
|
368 | - $already_localized[ $dependency['handle'] ] = true; |
|
367 | + wp_localize_script($dependency['handle'], $localize['name'], $data); |
|
368 | + $already_localized[$dependency['handle']] = true; |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -378,18 +378,18 @@ discard block |
||
378 | 378 | * Contains the type of the dependency at key |
379 | 379 | * 'dependency_type'. |
380 | 380 | */ |
381 | - protected function maybe_add_inline_script( $dependency, $context ) { |
|
382 | - if ( ! array_key_exists( 'add_inline', $dependency ) ) { |
|
381 | + protected function maybe_add_inline_script($dependency, $context) { |
|
382 | + if ( ! array_key_exists('add_inline', $dependency)) { |
|
383 | 383 | return; |
384 | 384 | } |
385 | 385 | |
386 | 386 | $inline_script = $dependency['add_inline']; |
387 | 387 | |
388 | - if ( is_callable( $inline_script ) ) { |
|
389 | - $inline_script = $inline_script( $context ); |
|
388 | + if (is_callable($inline_script)) { |
|
389 | + $inline_script = $inline_script($context); |
|
390 | 390 | } |
391 | 391 | |
392 | - wp_add_inline_script( $dependency['handle'], $inline_script ); |
|
392 | + wp_add_inline_script($dependency['handle'], $inline_script); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
@@ -401,10 +401,10 @@ discard block |
||
401 | 401 | * @param string $handle The dependency handle to enqueue. |
402 | 402 | * @return bool Returns whether the handle was found or not. |
403 | 403 | */ |
404 | - protected function enqueue_fallback_handle( $handle ) { |
|
404 | + protected function enqueue_fallback_handle($handle) { |
|
405 | 405 | $result = false; |
406 | - foreach ( $this->handlers as $handler ) { |
|
407 | - $result = $result || $handler->maybe_enqueue( $handle ); |
|
406 | + foreach ($this->handlers as $handler) { |
|
407 | + $result = $result || $handler->maybe_enqueue($handle); |
|
408 | 408 | } |
409 | 409 | return $result; |
410 | 410 | } |
@@ -419,9 +419,9 @@ discard block |
||
419 | 419 | * @param mixed $context Optional. The context to pass to the |
420 | 420 | * dependencies. |
421 | 421 | */ |
422 | - protected function enqueue_dependency_type( $dependencies, $dependency_type, $context = null ) { |
|
422 | + protected function enqueue_dependency_type($dependencies, $dependency_type, $context = null) { |
|
423 | 423 | $context['dependency_type'] = $dependency_type; |
424 | - array_walk( $dependencies, [ $this, 'enqueue_dependency' ], $context ); |
|
424 | + array_walk($dependencies, [$this, 'enqueue_dependency'], $context); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -434,9 +434,9 @@ discard block |
||
434 | 434 | * @param mixed $context Optional. The context to pass to the |
435 | 435 | * dependencies. |
436 | 436 | */ |
437 | - protected function register_dependency_type( $dependencies, $dependency_type, $context = null ) { |
|
437 | + protected function register_dependency_type($dependencies, $dependency_type, $context = null) { |
|
438 | 438 | $context['dependency_type'] = $dependency_type; |
439 | - array_walk( $dependencies, [ $this, 'register_dependency' ], $context ); |
|
439 | + array_walk($dependencies, [$this, 'register_dependency'], $context); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | /** |
@@ -451,12 +451,12 @@ discard block |
||
451 | 451 | * dependency at key |
452 | 452 | * 'dependency_type'. |
453 | 453 | */ |
454 | - protected function register_dependency( $dependency, $dependency_key, $context = null ) { |
|
455 | - $handler = $this->handlers[ $context['dependency_type'] ]; |
|
456 | - $handler->register( $dependency ); |
|
454 | + protected function register_dependency($dependency, $dependency_key, $context = null) { |
|
455 | + $handler = $this->handlers[$context['dependency_type']]; |
|
456 | + $handler->register($dependency); |
|
457 | 457 | |
458 | - if ( $this->enqueue_immediately ) { |
|
459 | - $this->register_enqueue_hooks( $dependency, $context ); |
|
458 | + if ($this->enqueue_immediately) { |
|
459 | + $this->register_enqueue_hooks($dependency, $context); |
|
460 | 460 | } |
461 | 461 | } |
462 | 462 | |
@@ -470,15 +470,15 @@ discard block |
||
470 | 470 | * Contains the type of the dependency at key |
471 | 471 | * 'dependency_type'. |
472 | 472 | */ |
473 | - protected function register_enqueue_hooks( $dependency, $context = null ) { |
|
474 | - $priority = $this->get_priority( $dependency ); |
|
473 | + protected function register_enqueue_hooks($dependency, $context = null) { |
|
474 | + $priority = $this->get_priority($dependency); |
|
475 | 475 | |
476 | - foreach ( [ 'wp_enqueue_scripts', 'admin_enqueue_scripts' ] as $hook ) { |
|
477 | - add_action( $hook, [ $this, 'enqueue' ], $priority, 1 ); |
|
476 | + foreach (['wp_enqueue_scripts', 'admin_enqueue_scripts'] as $hook) { |
|
477 | + add_action($hook, [$this, 'enqueue'], $priority, 1); |
|
478 | 478 | } |
479 | 479 | |
480 | - $this->maybe_localize( $dependency, $context ); |
|
481 | - $this->maybe_add_inline_script( $dependency, $context ); |
|
480 | + $this->maybe_localize($dependency, $context); |
|
481 | + $this->maybe_add_inline_script($dependency, $context); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | /** |
@@ -489,9 +489,9 @@ discard block |
||
489 | 489 | * @param array $dependency Configuration data of the dependency. |
490 | 490 | * @return int Priority to use. |
491 | 491 | */ |
492 | - protected function get_priority( $dependency ) { |
|
493 | - if ( array_key_exists( 'priority', $dependency ) ) { |
|
494 | - return intval( $dependency['priority'] ); |
|
492 | + protected function get_priority($dependency) { |
|
493 | + if (array_key_exists('priority', $dependency)) { |
|
494 | + return intval($dependency['priority']); |
|
495 | 495 | } |
496 | 496 | return 10; |
497 | 497 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param string $handle Handle of the dependency to enqueue. |
33 | 33 | * @return bool Whether the handle was found and enqueued. |
34 | 34 | */ |
35 | - public function maybe_enqueue( $handle ); |
|
35 | + public function maybe_enqueue($handle); |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Check whether a specific handle has been registered. |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param string $handle The handle to check |
43 | 43 | * @return bool Whether it is registered or not. |
44 | 44 | */ |
45 | - public function is_registered( $handle ); |
|
45 | + public function is_registered($handle); |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Check whether a specific handle has been enqueued. |
@@ -52,5 +52,5 @@ discard block |
||
52 | 52 | * @param string $handle The handle to check |
53 | 53 | * @return bool Whether it is enqueued or not. |
54 | 54 | */ |
55 | - public function is_enqueued( $handle ); |
|
55 | + public function is_enqueued($handle); |
|
56 | 56 | } |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * @param string $handle The handle to check |
52 | 52 | * @return bool Whether it is registered or not. |
53 | 53 | */ |
54 | - public function is_registered( $handle ) { |
|
55 | - return wp_script_is( $handle, 'registered' ); |
|
54 | + public function is_registered($handle) { |
|
55 | + return wp_script_is($handle, 'registered'); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param string $handle The handle to check |
64 | 64 | * @return bool Whether it is enqueued or not. |
65 | 65 | */ |
66 | - public function is_enqueued( $handle ) { |
|
67 | - return wp_script_is( $handle, 'enqueued' ); |
|
66 | + public function is_enqueued($handle) { |
|
67 | + return wp_script_is($handle, 'enqueued'); |
|
68 | 68 | } |
69 | 69 | } |