Lazy Load by WP Rocket - Version 2.3.2

Version Description

Bugfix: Incorrect characters used in Youtube thumbnail HTML code

Download this release

Release Info

Developer wp_media
Plugin Icon 128x128 Lazy Load by WP Rocket
Version 2.3.2
Comparing to
See all releases

Code changes from version 2.3.1 to 2.3.2

Files changed (42) hide show
  1. composer.lock +5 -5
  2. readme.txt +4 -1
  3. rocket-lazy-load.php +2 -2
  4. src/Dependencies/Interop/Container/ContainerInterface.php +15 -15
  5. src/Dependencies/Interop/Container/Exception/ContainerException.php +15 -15
  6. src/Dependencies/Interop/Container/Exception/NotFoundException.php +15 -15
  7. src/Dependencies/League/Container/Argument/ArgumentResolverInterface.php +26 -26
  8. src/Dependencies/League/Container/Argument/ArgumentResolverTrait.php +82 -82
  9. src/Dependencies/League/Container/Argument/RawArgument.php +27 -27
  10. src/Dependencies/League/Container/Argument/RawArgumentInterface.php +13 -13
  11. src/Dependencies/League/Container/Container.php +305 -305
  12. src/Dependencies/League/Container/ContainerAwareInterface.php +20 -20
  13. src/Dependencies/League/Container/ContainerAwareTrait.php +34 -34
  14. src/Dependencies/League/Container/ContainerInterface.php +59 -59
  15. src/Dependencies/League/Container/Definition/AbstractDefinition.php +62 -62
  16. src/Dependencies/League/Container/Definition/CallableDefinition.php +23 -23
  17. src/Dependencies/League/Container/Definition/ClassDefinition.php +67 -67
  18. src/Dependencies/League/Container/Definition/ClassDefinitionInterface.php +23 -23
  19. src/Dependencies/League/Container/Definition/DefinitionFactory.php +28 -28
  20. src/Dependencies/League/Container/Definition/DefinitionFactoryInterface.php +17 -17
  21. src/Dependencies/League/Container/Definition/DefinitionInterface.php +30 -30
  22. src/Dependencies/League/Container/Exception/NotFoundException.php +10 -10
  23. src/Dependencies/League/Container/ImmutableContainerAwareInterface.php +22 -22
  24. src/Dependencies/League/Container/ImmutableContainerAwareTrait.php +36 -36
  25. src/Dependencies/League/Container/ImmutableContainerInterface.php +10 -10
  26. src/Dependencies/League/Container/Inflector/Inflector.php +103 -103
  27. src/Dependencies/League/Container/Inflector/InflectorAggregate.php +53 -53
  28. src/Dependencies/League/Container/Inflector/InflectorAggregateInterface.php +25 -25
  29. src/Dependencies/League/Container/ReflectionContainer.php +87 -87
  30. src/Dependencies/League/Container/ServiceProvider/AbstractServiceProvider.php +27 -27
  31. src/Dependencies/League/Container/ServiceProvider/AbstractSignatureServiceProvider.php +31 -31
  32. src/Dependencies/League/Container/ServiceProvider/BootableServiceProviderInterface.php +14 -14
  33. src/Dependencies/League/Container/ServiceProvider/ServiceProviderAggregate.php +88 -88
  34. src/Dependencies/League/Container/ServiceProvider/ServiceProviderAggregateInterface.php +32 -32
  35. src/Dependencies/League/Container/ServiceProvider/ServiceProviderInterface.php +26 -26
  36. src/Dependencies/League/Container/ServiceProvider/SignatureServiceProviderInterface.php +24 -24
  37. src/Dependencies/Psr/Container/ContainerExceptionInterface.php +13 -13
  38. src/Dependencies/Psr/Container/ContainerInterface.php +37 -37
  39. src/Dependencies/Psr/Container/NotFoundExceptionInterface.php +13 -13
  40. src/Dependencies/RocketLazyload/Assets.php +299 -299
  41. src/Dependencies/RocketLazyload/Iframe.php +202 -202
  42. src/Dependencies/RocketLazyload/Image.php +474 -474
composer.lock CHANGED
@@ -275,16 +275,16 @@
275
  },
276
  {
277
  "name": "wp-media/rocket-lazyload-common",
278
- "version": "v2.5.1",
279
  "source": {
280
  "type": "git",
281
  "url": "https://github.com/wp-media/rocket-lazyload-common.git",
282
- "reference": "a5f1b59f822fd31bc7cb0fc368edecba96ceb71e"
283
  },
284
  "dist": {
285
  "type": "zip",
286
- "url": "https://api.github.com/repos/wp-media/rocket-lazyload-common/zipball/a5f1b59f822fd31bc7cb0fc368edecba96ceb71e",
287
- "reference": "a5f1b59f822fd31bc7cb0fc368edecba96ceb71e",
288
  "shasum": ""
289
  },
290
  "require": {
@@ -319,7 +319,7 @@
319
  }
320
  ],
321
  "description": "Common Code between WP Rocket and Lazyload by WP Rocket",
322
- "time": "2019-09-06T13:51:56+00:00"
323
  }
324
  ],
325
  "packages-dev": [
275
  },
276
  {
277
  "name": "wp-media/rocket-lazyload-common",
278
+ "version": "v2.5.2",
279
  "source": {
280
  "type": "git",
281
  "url": "https://github.com/wp-media/rocket-lazyload-common.git",
282
+ "reference": "37ca967029f6f86a207a9ae128c9e96bc95219d7"
283
  },
284
  "dist": {
285
  "type": "zip",
286
+ "url": "https://api.github.com/repos/wp-media/rocket-lazyload-common/zipball/37ca967029f6f86a207a9ae128c9e96bc95219d7",
287
+ "reference": "37ca967029f6f86a207a9ae128c9e96bc95219d7",
288
  "shasum": ""
289
  },
290
  "require": {
319
  }
320
  ],
321
  "description": "Common Code between WP Rocket and Lazyload by WP Rocket",
322
+ "time": "2019-09-07T12:37:44+00:00"
323
  }
324
  ],
325
  "packages-dev": [
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: lazyload, lazy load, images, iframes, thumbnail, thumbnails, smiley, smili
4
  Requires at least: 4.7
5
  Tested up to: 5.2
6
  Requires PHP: 5.6
7
- Stable tag: 2.3.1
8
 
9
  Lazy Load your images and iframes, replace Youtube videos by a preview thumbnail.
10
 
@@ -85,6 +85,9 @@ You can also apply it manually. The element you want to apply lazyload on must h
85
  The element must have the class `rocket-lazyload`, and a `data-bg` attribute, which value is the CSS url for the image.
86
 
87
  == Changelog ==
 
 
 
88
  = 2.3.1 =
89
  Bugfix: Prevent a conflict with WP Rocket
90
  Bugfix: apply loading="lazy" on Youtube thumbnail
4
  Requires at least: 4.7
5
  Tested up to: 5.2
6
  Requires PHP: 5.6
7
+ Stable tag: 2.3.2
8
 
9
  Lazy Load your images and iframes, replace Youtube videos by a preview thumbnail.
10
 
85
  The element must have the class `rocket-lazyload`, and a `data-bg` attribute, which value is the CSS url for the image.
86
 
87
  == Changelog ==
88
+ = 2.3.2 =
89
+ Bugfix: Incorrect characters used in Youtube thumbnail HTML code
90
+
91
  = 2.3.1 =
92
  Bugfix: Prevent a conflict with WP Rocket
93
  Bugfix: apply loading="lazy" on Youtube thumbnail
rocket-lazy-load.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Lazy Load by WP Rocket
4
  * Plugin URI: http://wordpress.org/plugins/rocket-lazy-load/
5
  * Description: The tiny Lazy Load script for WordPress without jQuery or others libraries.
6
- * Version: 2.3.1
7
  * Author: WP Rocket
8
  * Author URI: https://wp-rocket.me
9
  * Text Domain: rocket-lazy-load
@@ -29,7 +29,7 @@
29
 
30
  defined('ABSPATH') || die('Cheatin\' uh?');
31
 
32
- define('ROCKET_LL_VERSION', '2.3.1');
33
  define('ROCKET_LL_WP_VERSION', '4.7');
34
  define('ROCKET_LL_PHP_VERSION', '5.6');
35
  define('ROCKET_LL_BASENAME', plugin_basename(__FILE__));
3
  * Plugin Name: Lazy Load by WP Rocket
4
  * Plugin URI: http://wordpress.org/plugins/rocket-lazy-load/
5
  * Description: The tiny Lazy Load script for WordPress without jQuery or others libraries.
6
+ * Version: 2.3.2
7
  * Author: WP Rocket
8
  * Author URI: https://wp-rocket.me
9
  * Text Domain: rocket-lazy-load
29
 
30
  defined('ABSPATH') || die('Cheatin\' uh?');
31
 
32
+ define('ROCKET_LL_VERSION', '2.3.2');
33
  define('ROCKET_LL_WP_VERSION', '4.7');
34
  define('ROCKET_LL_PHP_VERSION', '5.6');
35
  define('ROCKET_LL_BASENAME', plugin_basename(__FILE__));
src/Dependencies/Interop/Container/ContainerInterface.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
- /**
3
- * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
4
- */
5
-
6
- namespace RocketLazyLoadPlugin\Dependencies\Interop\Container;
7
-
8
- use RocketLazyLoadPlugin\Dependencies\Psr\Container\ContainerInterface as PsrContainerInterface;
9
-
10
- /**
11
- * Describes the interface of a container that exposes methods to read its entries.
12
- */
13
- interface ContainerInterface extends PsrContainerInterface
14
- {
15
- }
1
+ <?php
2
+ /**
3
+ * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
4
+ */
5
+
6
+ namespace RocketLazyLoadPlugin\Dependencies\Interop\Container;
7
+
8
+ use RocketLazyLoadPlugin\Dependencies\Psr\Container\ContainerInterface as PsrContainerInterface;
9
+
10
+ /**
11
+ * Describes the interface of a container that exposes methods to read its entries.
12
+ */
13
+ interface ContainerInterface extends PsrContainerInterface
14
+ {
15
+ }
src/Dependencies/Interop/Container/Exception/ContainerException.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
- /**
3
- * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
4
- */
5
-
6
- namespace RocketLazyLoadPlugin\Dependencies\Interop\Container\Exception;
7
-
8
- use RocketLazyLoadPlugin\Dependencies\Psr\Container\ContainerExceptionInterface as PsrContainerException;
9
-
10
- /**
11
- * Base interface representing a generic exception in a container.
12
- */
13
- interface ContainerException extends PsrContainerException
14
- {
15
- }
1
+ <?php
2
+ /**
3
+ * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
4
+ */
5
+
6
+ namespace RocketLazyLoadPlugin\Dependencies\Interop\Container\Exception;
7
+
8
+ use RocketLazyLoadPlugin\Dependencies\Psr\Container\ContainerExceptionInterface as PsrContainerException;
9
+
10
+ /**
11
+ * Base interface representing a generic exception in a container.
12
+ */
13
+ interface ContainerException extends PsrContainerException
14
+ {
15
+ }
src/Dependencies/Interop/Container/Exception/NotFoundException.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
- /**
3
- * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
4
- */
5
-
6
- namespace RocketLazyLoadPlugin\Dependencies\Interop\Container\Exception;
7
-
8
- use RocketLazyLoadPlugin\Dependencies\Psr\Container\NotFoundExceptionInterface as PsrNotFoundException;
9
-
10
- /**
11
- * No entry was found in the container.
12
- */
13
- interface NotFoundException extends ContainerException, PsrNotFoundException
14
- {
15
- }
1
+ <?php
2
+ /**
3
+ * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
4
+ */
5
+
6
+ namespace RocketLazyLoadPlugin\Dependencies\Interop\Container\Exception;
7
+
8
+ use RocketLazyLoadPlugin\Dependencies\Psr\Container\NotFoundExceptionInterface as PsrNotFoundException;
9
+
10
+ /**
11
+ * No entry was found in the container.
12
+ */
13
+ interface NotFoundException extends ContainerException, PsrNotFoundException
14
+ {
15
+ }
src/Dependencies/League/Container/Argument/ArgumentResolverInterface.php CHANGED
@@ -1,26 +1,26 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Argument;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareInterface;
6
- use ReflectionFunctionAbstract;
7
-
8
- interface ArgumentResolverInterface extends ImmutableContainerAwareInterface
9
- {
10
- /**
11
- * Resolve an array of arguments to their concrete implementations.
12
- *
13
- * @param array $arguments
14
- * @return array
15
- */
16
- public function resolveArguments(array $arguments);
17
-
18
- /**
19
- * Resolves the correct arguments to be passed to a method.
20
- *
21
- * @param \ReflectionFunctionAbstract $method
22
- * @param array $args
23
- * @return array
24
- */
25
- public function reflectArguments(ReflectionFunctionAbstract $method, array $args = []);
26
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Argument;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareInterface;
6
+ use ReflectionFunctionAbstract;
7
+
8
+ interface ArgumentResolverInterface extends ImmutableContainerAwareInterface
9
+ {
10
+ /**
11
+ * Resolve an array of arguments to their concrete implementations.
12
+ *
13
+ * @param array $arguments
14
+ * @return array
15
+ */
16
+ public function resolveArguments(array $arguments);
17
+
18
+ /**
19
+ * Resolves the correct arguments to be passed to a method.
20
+ *
21
+ * @param \ReflectionFunctionAbstract $method
22
+ * @param array $args
23
+ * @return array
24
+ */
25
+ public function reflectArguments(ReflectionFunctionAbstract $method, array $args = []);
26
+ }
src/Dependencies/League/Container/Argument/ArgumentResolverTrait.php CHANGED
@@ -1,82 +1,82 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Argument;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\Exception\NotFoundException;
6
- use RocketLazyLoadPlugin\Dependencies\League\Container\ReflectionContainer;
7
- use ReflectionFunctionAbstract;
8
- use ReflectionParameter;
9
-
10
- trait ArgumentResolverTrait
11
- {
12
- /**
13
- * {@inheritdoc}
14
- */
15
- public function resolveArguments(array $arguments)
16
- {
17
- foreach ($arguments as &$arg) {
18
- if ($arg instanceof RawArgumentInterface) {
19
- $arg = $arg->getValue();
20
- continue;
21
- }
22
-
23
- if (! is_string($arg)) {
24
- continue;
25
- }
26
-
27
- $container = $this->getContainer();
28
-
29
- if (is_null($container) && $this instanceof ReflectionContainer) {
30
- $container = $this;
31
- }
32
-
33
- if (! is_null($container) && $container->has($arg)) {
34
- $arg = $container->get($arg);
35
-
36
- if ($arg instanceof RawArgumentInterface) {
37
- $arg = $arg->getValue();
38
- }
39
-
40
- continue;
41
- }
42
- }
43
-
44
- return $arguments;
45
- }
46
-
47
- /**
48
- * {@inheritdoc}
49
- */
50
- public function reflectArguments(ReflectionFunctionAbstract $method, array $args = [])
51
- {
52
- $arguments = array_map(function (ReflectionParameter $param) use ($method, $args) {
53
- $name = $param->getName();
54
- $class = $param->getClass();
55
-
56
- if (array_key_exists($name, $args)) {
57
- return $args[$name];
58
- }
59
-
60
- if (! is_null($class)) {
61
- return $class->getName();
62
- }
63
-
64
- if ($param->isDefaultValueAvailable()) {
65
- return $param->getDefaultValue();
66
- }
67
-
68
- throw new NotFoundException(sprintf(
69
- 'Unable to resolve a value for parameter (%s) in the function/method (%s)',
70
- $name,
71
- $method->getName()
72
- ));
73
- }, $method->getParameters());
74
-
75
- return $this->resolveArguments($arguments);
76
- }
77
-
78
- /**
79
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface
80
- */
81
- abstract public function getContainer();
82
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Argument;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Exception\NotFoundException;
6
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ReflectionContainer;
7
+ use ReflectionFunctionAbstract;
8
+ use ReflectionParameter;
9
+
10
+ trait ArgumentResolverTrait
11
+ {
12
+ /**
13
+ * {@inheritdoc}
14
+ */
15
+ public function resolveArguments(array $arguments)
16
+ {
17
+ foreach ($arguments as &$arg) {
18
+ if ($arg instanceof RawArgumentInterface) {
19
+ $arg = $arg->getValue();
20
+ continue;
21
+ }
22
+
23
+ if (! is_string($arg)) {
24
+ continue;
25
+ }
26
+
27
+ $container = $this->getContainer();
28
+
29
+ if (is_null($container) && $this instanceof ReflectionContainer) {
30
+ $container = $this;
31
+ }
32
+
33
+ if (! is_null($container) && $container->has($arg)) {
34
+ $arg = $container->get($arg);
35
+
36
+ if ($arg instanceof RawArgumentInterface) {
37
+ $arg = $arg->getValue();
38
+ }
39
+
40
+ continue;
41
+ }
42
+ }
43
+
44
+ return $arguments;
45
+ }
46
+
47
+ /**
48
+ * {@inheritdoc}
49
+ */
50
+ public function reflectArguments(ReflectionFunctionAbstract $method, array $args = [])
51
+ {
52
+ $arguments = array_map(function (ReflectionParameter $param) use ($method, $args) {
53
+ $name = $param->getName();
54
+ $class = $param->getClass();
55
+
56
+ if (array_key_exists($name, $args)) {
57
+ return $args[$name];
58
+ }
59
+
60
+ if (! is_null($class)) {
61
+ return $class->getName();
62
+ }
63
+
64
+ if ($param->isDefaultValueAvailable()) {
65
+ return $param->getDefaultValue();
66
+ }
67
+
68
+ throw new NotFoundException(sprintf(
69
+ 'Unable to resolve a value for parameter (%s) in the function/method (%s)',
70
+ $name,
71
+ $method->getName()
72
+ ));
73
+ }, $method->getParameters());
74
+
75
+ return $this->resolveArguments($arguments);
76
+ }
77
+
78
+ /**
79
+ * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface
80
+ */
81
+ abstract public function getContainer();
82
+ }
src/Dependencies/League/Container/Argument/RawArgument.php CHANGED
@@ -1,27 +1,27 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Argument;
4
-
5
- class RawArgument implements RawArgumentInterface
6
- {
7
- /**
8
- * @var mixed
9
- */
10
- protected $value;
11
-
12
- /**
13
- * {@inheritdoc}
14
- */
15
- public function __construct($value)
16
- {
17
- $this->value = $value;
18
- }
19
-
20
- /**
21
- * {@inheritdoc}
22
- */
23
- public function getValue()
24
- {
25
- return $this->value;
26
- }
27
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Argument;
4
+
5
+ class RawArgument implements RawArgumentInterface
6
+ {
7
+ /**
8
+ * @var mixed
9
+ */
10
+ protected $value;
11
+
12
+ /**
13
+ * {@inheritdoc}
14
+ */
15
+ public function __construct($value)
16
+ {
17
+ $this->value = $value;
18
+ }
19
+
20
+ /**
21
+ * {@inheritdoc}
22
+ */
23
+ public function getValue()
24
+ {
25
+ return $this->value;
26
+ }
27
+ }
src/Dependencies/League/Container/Argument/RawArgumentInterface.php CHANGED
@@ -1,13 +1,13 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Argument;
4
-
5
- interface RawArgumentInterface
6
- {
7
- /**
8
- * Return the value of the raw argument.
9
- *
10
- * @return mixed
11
- */
12
- public function getValue();
13
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Argument;
4
+
5
+ interface RawArgumentInterface
6
+ {
7
+ /**
8
+ * Return the value of the raw argument.
9
+ *
10
+ * @return mixed
11
+ */
12
+ public function getValue();
13
+ }
src/Dependencies/League/Container/Container.php CHANGED
@@ -1,305 +1,305 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface as InteropContainerInterface;
6
- use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\RawArgumentInterface;
7
- use RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionFactory;
8
- use RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionFactoryInterface;
9
- use RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface;
10
- use RocketLazyLoadPlugin\Dependencies\League\Container\Exception\NotFoundException;
11
- use RocketLazyLoadPlugin\Dependencies\League\Container\Inflector\InflectorAggregate;
12
- use RocketLazyLoadPlugin\Dependencies\League\Container\Inflector\InflectorAggregateInterface;
13
- use RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderAggregate;
14
- use RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderAggregateInterface;
15
-
16
- class Container implements ContainerInterface
17
- {
18
- /**
19
- * @var \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionFactoryInterface
20
- */
21
- protected $definitionFactory;
22
-
23
- /**
24
- * @var \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface[]
25
- */
26
- protected $definitions = [];
27
-
28
- /**
29
- * @var \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface[]
30
- */
31
- protected $sharedDefinitions = [];
32
-
33
- /**
34
- * @var \RocketLazyLoadPlugin\Dependencies\League\Container\Inflector\InflectorAggregateInterface
35
- */
36
- protected $inflectors;
37
-
38
- /**
39
- * @var \RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderAggregateInterface
40
- */
41
- protected $providers;
42
-
43
- /**
44
- * @var array
45
- */
46
- protected $shared = [];
47
-
48
- /**
49
- * @var \RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface[]
50
- */
51
- protected $delegates = [];
52
-
53
- /**
54
- * Constructor.
55
- *
56
- * @param \RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderAggregateInterface|null $providers
57
- * @param \RocketLazyLoadPlugin\Dependencies\League\Container\Inflector\InflectorAggregateInterface|null $inflectors
58
- * @param \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionFactoryInterface|null $definitionFactory
59
- */
60
- public function __construct(
61
- ServiceProviderAggregateInterface $providers = null,
62
- InflectorAggregateInterface $inflectors = null,
63
- DefinitionFactoryInterface $definitionFactory = null
64
- ) {
65
- // set required dependencies
66
- $this->providers = (is_null($providers))
67
- ? (new ServiceProviderAggregate)->setContainer($this)
68
- : $providers->setContainer($this);
69
-
70
- $this->inflectors = (is_null($inflectors))
71
- ? (new InflectorAggregate)->setContainer($this)
72
- : $inflectors->setContainer($this);
73
-
74
- $this->definitionFactory = (is_null($definitionFactory))
75
- ? (new DefinitionFactory)->setContainer($this)
76
- : $definitionFactory->setContainer($this);
77
- }
78
-
79
- /**
80
- * {@inheritdoc}
81
- */
82
- public function get($alias, array $args = [])
83
- {
84
- try {
85
- return $this->getFromThisContainer($alias, $args);
86
- } catch (NotFoundException $exception) {
87
- if ($this->providers->provides($alias)) {
88
- $this->providers->register($alias);
89
-
90
- return $this->getFromThisContainer($alias, $args);
91
- }
92
-
93
- $resolved = $this->getFromDelegate($alias, $args);
94
-
95
- return $this->inflectors->inflect($resolved);
96
- }
97
- }
98
-
99
- /**
100
- * {@inheritdoc}
101
- */
102
- public function has($alias)
103
- {
104
- if (array_key_exists($alias, $this->definitions) || $this->hasShared($alias)) {
105
- return true;
106
- }
107
-
108
- if ($this->providers->provides($alias)) {
109
- return true;
110
- }
111
-
112
- return $this->hasInDelegate($alias);
113
- }
114
-
115
- /**
116
- * Returns a boolean to determine if the container has a shared instance of an alias.
117
- *
118
- * @param string $alias
119
- * @param boolean $resolved
120
- * @return boolean
121
- */
122
- public function hasShared($alias, $resolved = false)
123
- {
124
- $shared = ($resolved === false) ? array_merge($this->shared, $this->sharedDefinitions) : $this->shared;
125
-
126
- return (array_key_exists($alias, $shared));
127
- }
128
-
129
- /**
130
- * {@inheritdoc}
131
- */
132
- public function add($alias, $concrete = null, $share = false)
133
- {
134
- unset($this->shared[$alias]);
135
- unset($this->definitions[$alias]);
136
- unset($this->sharedDefinitions[$alias]);
137
-
138
- if (is_null($concrete)) {
139
- $concrete = $alias;
140
- }
141
-
142
- $definition = $this->definitionFactory->getDefinition($alias, $concrete);
143
-
144
- if ($definition instanceof DefinitionInterface) {
145
- if ($share === false) {
146
- $this->definitions[$alias] = $definition;
147
- } else {
148
- $this->sharedDefinitions[$alias] = $definition;
149
- }
150
-
151
- return $definition;
152
- }
153
-
154
- // dealing with a value that cannot build a definition
155
- $this->shared[$alias] = $concrete;
156
- }
157
-
158
- /**
159
- * {@inheritdoc}
160
- */
161
- public function share($alias, $concrete = null)
162
- {
163
- return $this->add($alias, $concrete, true);
164
- }
165
-
166
- /**
167
- * {@inheritdoc}
168
- */
169
- public function addServiceProvider($provider)
170
- {
171
- $this->providers->add($provider);
172
-
173
- return $this;
174
- }
175
-
176
- /**
177
- * {@inheritdoc}
178
- */
179
- public function extend($alias)
180
- {
181
- if ($this->providers->provides($alias)) {
182
- $this->providers->register($alias);
183
- }
184
-
185
- if (array_key_exists($alias, $this->definitions)) {
186
- return $this->definitions[$alias];
187
- }
188
-
189
- if (array_key_exists($alias, $this->sharedDefinitions)) {
190
- return $this->sharedDefinitions[$alias];
191
- }
192
-
193
- throw new NotFoundException(
194
- sprintf('Unable to extend alias (%s) as it is not being managed as a definition', $alias)
195
- );
196
- }
197
-
198
- /**
199
- * {@inheritdoc}
200
- */
201
- public function inflector($type, callable $callback = null)
202
- {
203
- return $this->inflectors->add($type, $callback);
204
- }
205
-
206
- /**
207
- * {@inheritdoc}
208
- */
209
- public function call(callable $callable, array $args = [])
210
- {
211
- return (new ReflectionContainer)->setContainer($this)->call($callable, $args);
212
- }
213
-
214
- /**
215
- * Delegate a backup container to be checked for services if it
216
- * cannot be resolved via this container.
217
- *
218
- * @param \RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface $container
219
- * @return $this
220
- */
221
- public function delegate(InteropContainerInterface $container)
222
- {
223
- $this->delegates[] = $container;
224
-
225
- if ($container instanceof ImmutableContainerAwareInterface) {
226
- $container->setContainer($this);
227
- }
228
-
229
- return $this;
230
- }
231
-
232
- /**
233
- * Returns true if service is registered in one of the delegated backup containers.
234
- *
235
- * @param string $alias
236
- * @return boolean
237
- */
238
- public function hasInDelegate($alias)
239
- {
240
- foreach ($this->delegates as $container) {
241
- if ($container->has($alias)) {
242
- return true;
243
- }
244
- }
245
-
246
- return false;
247
- }
248
-
249
- /**
250
- * Attempt to get a service from the stack of delegated backup containers.
251
- *
252
- * @param string $alias
253
- * @param array $args
254
- * @return mixed
255
- */
256
- protected function getFromDelegate($alias, array $args = [])
257
- {
258
- foreach ($this->delegates as $container) {
259
- if ($container->has($alias)) {
260
- return $container->get($alias, $args);
261
- }
262
-
263
- continue;
264
- }
265
-
266
- throw new NotFoundException(
267
- sprintf('Alias (%s) is not being managed by the container', $alias)
268
- );
269
-
270
- }
271
-
272
- /**
273
- * Get a service that has been registered in this container.
274
- *
275
- * @param string $alias
276
- * @param array $args
277
- * @return mixed
278
- */
279
- protected function getFromThisContainer($alias, array $args = [])
280
- {
281
- if ($this->hasShared($alias, true)) {
282
- $shared = $this->inflectors->inflect($this->shared[$alias]);
283
- if ($shared instanceof RawArgumentInterface) {
284
- return $shared->getValue();
285
- }
286
- return $shared;
287
- }
288
-
289
- if (array_key_exists($alias, $this->sharedDefinitions)) {
290
- $shared = $this->inflectors->inflect($this->sharedDefinitions[$alias]->build());
291
- $this->shared[$alias] = $shared;
292
- return $shared;
293
- }
294
-
295
- if (array_key_exists($alias, $this->definitions)) {
296
- return $this->inflectors->inflect(
297
- $this->definitions[$alias]->build($args)
298
- );
299
- }
300
-
301
- throw new NotFoundException(
302
- sprintf('Alias (%s) is not being managed by the container', $alias)
303
- );
304
- }
305
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface as InteropContainerInterface;
6
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\RawArgumentInterface;
7
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionFactory;
8
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionFactoryInterface;
9
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface;
10
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Exception\NotFoundException;
11
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Inflector\InflectorAggregate;
12
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Inflector\InflectorAggregateInterface;
13
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderAggregate;
14
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderAggregateInterface;
15
+
16
+ class Container implements ContainerInterface
17
+ {
18
+ /**
19
+ * @var \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionFactoryInterface
20
+ */
21
+ protected $definitionFactory;
22
+
23
+ /**
24
+ * @var \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface[]
25
+ */
26
+ protected $definitions = [];
27
+
28
+ /**
29
+ * @var \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface[]
30
+ */
31
+ protected $sharedDefinitions = [];
32
+
33
+ /**
34
+ * @var \RocketLazyLoadPlugin\Dependencies\League\Container\Inflector\InflectorAggregateInterface
35
+ */
36
+ protected $inflectors;
37
+
38
+ /**
39
+ * @var \RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderAggregateInterface
40
+ */
41
+ protected $providers;
42
+
43
+ /**
44
+ * @var array
45
+ */
46
+ protected $shared = [];
47
+
48
+ /**
49
+ * @var \RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface[]
50
+ */
51
+ protected $delegates = [];
52
+
53
+ /**
54
+ * Constructor.
55
+ *
56
+ * @param \RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderAggregateInterface|null $providers
57
+ * @param \RocketLazyLoadPlugin\Dependencies\League\Container\Inflector\InflectorAggregateInterface|null $inflectors
58
+ * @param \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionFactoryInterface|null $definitionFactory
59
+ */
60
+ public function __construct(
61
+ ServiceProviderAggregateInterface $providers = null,
62
+ InflectorAggregateInterface $inflectors = null,
63
+ DefinitionFactoryInterface $definitionFactory = null
64
+ ) {
65
+ // set required dependencies
66
+ $this->providers = (is_null($providers))
67
+ ? (new ServiceProviderAggregate)->setContainer($this)
68
+ : $providers->setContainer($this);
69
+
70
+ $this->inflectors = (is_null($inflectors))
71
+ ? (new InflectorAggregate)->setContainer($this)
72
+ : $inflectors->setContainer($this);
73
+
74
+ $this->definitionFactory = (is_null($definitionFactory))
75
+ ? (new DefinitionFactory)->setContainer($this)
76
+ : $definitionFactory->setContainer($this);
77
+ }
78
+
79
+ /**
80
+ * {@inheritdoc}
81
+ */
82
+ public function get($alias, array $args = [])
83
+ {
84
+ try {
85
+ return $this->getFromThisContainer($alias, $args);
86
+ } catch (NotFoundException $exception) {
87
+ if ($this->providers->provides($alias)) {
88
+ $this->providers->register($alias);
89
+
90
+ return $this->getFromThisContainer($alias, $args);
91
+ }
92
+
93
+ $resolved = $this->getFromDelegate($alias, $args);
94
+
95
+ return $this->inflectors->inflect($resolved);
96
+ }
97
+ }
98
+
99
+ /**
100
+ * {@inheritdoc}
101
+ */
102
+ public function has($alias)
103
+ {
104
+ if (array_key_exists($alias, $this->definitions) || $this->hasShared($alias)) {
105
+ return true;
106
+ }
107
+
108
+ if ($this->providers->provides($alias)) {
109
+ return true;
110
+ }
111
+
112
+ return $this->hasInDelegate($alias);
113
+ }
114
+
115
+ /**
116
+ * Returns a boolean to determine if the container has a shared instance of an alias.
117
+ *
118
+ * @param string $alias
119
+ * @param boolean $resolved
120
+ * @return boolean
121
+ */
122
+ public function hasShared($alias, $resolved = false)
123
+ {
124
+ $shared = ($resolved === false) ? array_merge($this->shared, $this->sharedDefinitions) : $this->shared;
125
+
126
+ return (array_key_exists($alias, $shared));
127
+ }
128
+
129
+ /**
130
+ * {@inheritdoc}
131
+ */
132
+ public function add($alias, $concrete = null, $share = false)
133
+ {
134
+ unset($this->shared[$alias]);
135
+ unset($this->definitions[$alias]);
136
+ unset($this->sharedDefinitions[$alias]);
137
+
138
+ if (is_null($concrete)) {
139
+ $concrete = $alias;
140
+ }
141
+
142
+ $definition = $this->definitionFactory->getDefinition($alias, $concrete);
143
+
144
+ if ($definition instanceof DefinitionInterface) {
145
+ if ($share === false) {
146
+ $this->definitions[$alias] = $definition;
147
+ } else {
148
+ $this->sharedDefinitions[$alias] = $definition;
149
+ }
150
+
151
+ return $definition;
152
+ }
153
+
154
+ // dealing with a value that cannot build a definition
155
+ $this->shared[$alias] = $concrete;
156
+ }
157
+
158
+ /**
159
+ * {@inheritdoc}
160
+ */
161
+ public function share($alias, $concrete = null)
162
+ {
163
+ return $this->add($alias, $concrete, true);
164
+ }
165
+
166
+ /**
167
+ * {@inheritdoc}
168
+ */
169
+ public function addServiceProvider($provider)
170
+ {
171
+ $this->providers->add($provider);
172
+
173
+ return $this;
174
+ }
175
+
176
+ /**
177
+ * {@inheritdoc}
178
+ */
179
+ public function extend($alias)
180
+ {
181
+ if ($this->providers->provides($alias)) {
182
+ $this->providers->register($alias);
183
+ }
184
+
185
+ if (array_key_exists($alias, $this->definitions)) {
186
+ return $this->definitions[$alias];
187
+ }
188
+
189
+ if (array_key_exists($alias, $this->sharedDefinitions)) {
190
+ return $this->sharedDefinitions[$alias];
191
+ }
192
+
193
+ throw new NotFoundException(
194
+ sprintf('Unable to extend alias (%s) as it is not being managed as a definition', $alias)
195
+ );
196
+ }
197
+
198
+ /**
199
+ * {@inheritdoc}
200
+ */
201
+ public function inflector($type, callable $callback = null)
202
+ {
203
+ return $this->inflectors->add($type, $callback);
204
+ }
205
+
206
+ /**
207
+ * {@inheritdoc}
208
+ */
209
+ public function call(callable $callable, array $args = [])
210
+ {
211
+ return (new ReflectionContainer)->setContainer($this)->call($callable, $args);
212
+ }
213
+
214
+ /**
215
+ * Delegate a backup container to be checked for services if it
216
+ * cannot be resolved via this container.
217
+ *
218
+ * @param \RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface $container
219
+ * @return $this
220
+ */
221
+ public function delegate(InteropContainerInterface $container)
222
+ {
223
+ $this->delegates[] = $container;
224
+
225
+ if ($container instanceof ImmutableContainerAwareInterface) {
226
+ $container->setContainer($this);
227
+ }
228
+
229
+ return $this;
230
+ }
231
+
232
+ /**
233
+ * Returns true if service is registered in one of the delegated backup containers.
234
+ *
235
+ * @param string $alias
236
+ * @return boolean
237
+ */
238
+ public function hasInDelegate($alias)
239
+ {
240
+ foreach ($this->delegates as $container) {
241
+ if ($container->has($alias)) {
242
+ return true;
243
+ }
244
+ }
245
+
246
+ return false;
247
+ }
248
+
249
+ /**
250
+ * Attempt to get a service from the stack of delegated backup containers.
251
+ *
252
+ * @param string $alias
253
+ * @param array $args
254
+ * @return mixed
255
+ */
256
+ protected function getFromDelegate($alias, array $args = [])
257
+ {
258
+ foreach ($this->delegates as $container) {
259
+ if ($container->has($alias)) {
260
+ return $container->get($alias, $args);
261
+ }
262
+
263
+ continue;
264
+ }
265
+
266
+ throw new NotFoundException(
267
+ sprintf('Alias (%s) is not being managed by the container', $alias)
268
+ );
269
+
270
+ }
271
+
272
+ /**
273
+ * Get a service that has been registered in this container.
274
+ *
275
+ * @param string $alias
276
+ * @param array $args
277
+ * @return mixed
278
+ */
279
+ protected function getFromThisContainer($alias, array $args = [])
280
+ {
281
+ if ($this->hasShared($alias, true)) {
282
+ $shared = $this->inflectors->inflect($this->shared[$alias]);
283
+ if ($shared instanceof RawArgumentInterface) {
284
+ return $shared->getValue();
285
+ }
286
+ return $shared;
287
+ }
288
+
289
+ if (array_key_exists($alias, $this->sharedDefinitions)) {
290
+ $shared = $this->inflectors->inflect($this->sharedDefinitions[$alias]->build());
291
+ $this->shared[$alias] = $shared;
292
+ return $shared;
293
+ }
294
+
295
+ if (array_key_exists($alias, $this->definitions)) {
296
+ return $this->inflectors->inflect(
297
+ $this->definitions[$alias]->build($args)
298
+ );
299
+ }
300
+
301
+ throw new NotFoundException(
302
+ sprintf('Alias (%s) is not being managed by the container', $alias)
303
+ );
304
+ }
305
+ }
src/Dependencies/League/Container/ContainerAwareInterface.php CHANGED
@@ -1,20 +1,20 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
-
5
- interface ContainerAwareInterface
6
- {
7
- /**
8
- * Set a container
9
- *
10
- * @param \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface $container
11
- */
12
- public function setContainer(ContainerInterface $container);
13
-
14
- /**
15
- * Get the container
16
- *
17
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface
18
- */
19
- public function getContainer();
20
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
+
5
+ interface ContainerAwareInterface
6
+ {
7
+ /**
8
+ * Set a container
9
+ *
10
+ * @param \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface $container
11
+ */
12
+ public function setContainer(ContainerInterface $container);
13
+
14
+ /**
15
+ * Get the container
16
+ *
17
+ * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface
18
+ */
19
+ public function getContainer();
20
+ }
src/Dependencies/League/Container/ContainerAwareTrait.php CHANGED
@@ -1,34 +1,34 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
-
5
- trait ContainerAwareTrait
6
- {
7
- /**
8
- * @var \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface
9
- */
10
- protected $container;
11
-
12
- /**
13
- * Set a container.
14
- *
15
- * @param \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface $container
16
- * @return $this
17
- */
18
- public function setContainer(ContainerInterface $container)
19
- {
20
- $this->container = $container;
21
-
22
- return $this;
23
- }
24
-
25
- /**
26
- * Get the container.
27
- *
28
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface
29
- */
30
- public function getContainer()
31
- {
32
- return $this->container;
33
- }
34
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
+
5
+ trait ContainerAwareTrait
6
+ {
7
+ /**
8
+ * @var \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface
9
+ */
10
+ protected $container;
11
+
12
+ /**
13
+ * Set a container.
14
+ *
15
+ * @param \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface $container
16
+ * @return $this
17
+ */
18
+ public function setContainer(ContainerInterface $container)
19
+ {
20
+ $this->container = $container;
21
+
22
+ return $this;
23
+ }
24
+
25
+ /**
26
+ * Get the container.
27
+ *
28
+ * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface
29
+ */
30
+ public function getContainer()
31
+ {
32
+ return $this->container;
33
+ }
34
+ }
src/Dependencies/League/Container/ContainerInterface.php CHANGED
@@ -1,59 +1,59 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
-
5
- interface ContainerInterface extends ImmutableContainerInterface
6
- {
7
- /**
8
- * Add an item to the container.
9
- *
10
- * @param string $alias
11
- * @param mixed|null $concrete
12
- * @param boolean $share
13
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface
14
- */
15
- public function add($alias, $concrete = null, $share = false);
16
-
17
- /**
18
- * Convenience method to add an item to the container as a shared item.
19
- *
20
- * @param string $alias
21
- * @param mixed|null $concrete
22
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface
23
- */
24
- public function share($alias, $concrete = null);
25
-
26
- /**
27
- * Add a service provider to the container.
28
- *
29
- * @param string|\RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderInterface $provider
30
- * @return void
31
- */
32
- public function addServiceProvider($provider);
33
-
34
- /**
35
- * Returns a definition of an item to be extended.
36
- *
37
- * @param string $alias
38
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface
39
- */
40
- public function extend($alias);
41
-
42
- /**
43
- * Allows for manipulation of specific types on resolution.
44
- *
45
- * @param string $type
46
- * @param callable|null $callback
47
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\Inflector\Inflector|void
48
- */
49
- public function inflector($type, callable $callback = null);
50
-
51
- /**
52
- * Invoke a callable via the container.
53
- *
54
- * @param callable $callable
55
- * @param array $args
56
- * @return mixed
57
- */
58
- public function call(callable $callable, array $args = []);
59
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
+
5
+ interface ContainerInterface extends ImmutableContainerInterface
6
+ {
7
+ /**
8
+ * Add an item to the container.
9
+ *
10
+ * @param string $alias
11
+ * @param mixed|null $concrete
12
+ * @param boolean $share
13
+ * @return \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface
14
+ */
15
+ public function add($alias, $concrete = null, $share = false);
16
+
17
+ /**
18
+ * Convenience method to add an item to the container as a shared item.
19
+ *
20
+ * @param string $alias
21
+ * @param mixed|null $concrete
22
+ * @return \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface
23
+ */
24
+ public function share($alias, $concrete = null);
25
+
26
+ /**
27
+ * Add a service provider to the container.
28
+ *
29
+ * @param string|\RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderInterface $provider
30
+ * @return void
31
+ */
32
+ public function addServiceProvider($provider);
33
+
34
+ /**
35
+ * Returns a definition of an item to be extended.
36
+ *
37
+ * @param string $alias
38
+ * @return \RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface
39
+ */
40
+ public function extend($alias);
41
+
42
+ /**
43
+ * Allows for manipulation of specific types on resolution.
44
+ *
45
+ * @param string $type
46
+ * @param callable|null $callback
47
+ * @return \RocketLazyLoadPlugin\Dependencies\League\Container\Inflector\Inflector|void
48
+ */
49
+ public function inflector($type, callable $callback = null);
50
+
51
+ /**
52
+ * Invoke a callable via the container.
53
+ *
54
+ * @param callable $callable
55
+ * @param array $args
56
+ * @return mixed
57
+ */
58
+ public function call(callable $callable, array $args = []);
59
+ }
src/Dependencies/League/Container/Definition/AbstractDefinition.php CHANGED
@@ -1,62 +1,62 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\ArgumentResolverInterface;
6
- use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\ArgumentResolverTrait;
7
- use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareTrait;
8
-
9
- abstract class AbstractDefinition implements ArgumentResolverInterface, DefinitionInterface
10
- {
11
- use ArgumentResolverTrait;
12
- use ImmutableContainerAwareTrait;
13
-
14
- /**
15
- * @var string
16
- */
17
- protected $alias;
18
-
19
- /**
20
- * @var mixed
21
- */
22
- protected $concrete;
23
-
24
- /**
25
- * @var array
26
- */
27
- protected $arguments = [];
28
-
29
- /**
30
- * Constructor.
31
- *
32
- * @param string $alias
33
- * @param mixed $concrete
34
- */
35
- public function __construct($alias, $concrete)
36
- {
37
- $this->alias = $alias;
38
- $this->concrete = $concrete;
39
- }
40
-
41
- /**
42
- * {@inheritdoc}
43
- */
44
- public function withArgument($arg)
45
- {
46
- $this->arguments[] = $arg;
47
-
48
- return $this;
49
- }
50
-
51
- /**
52
- * {@inheritdoc}
53
- */
54
- public function withArguments(array $args)
55
- {
56
- foreach ($args as $arg) {
57
- $this->withArgument($arg);
58
- }
59
-
60
- return $this;
61
- }
62
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\ArgumentResolverInterface;
6
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\ArgumentResolverTrait;
7
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareTrait;
8
+
9
+ abstract class AbstractDefinition implements ArgumentResolverInterface, DefinitionInterface
10
+ {
11
+ use ArgumentResolverTrait;
12
+ use ImmutableContainerAwareTrait;
13
+
14
+ /**
15
+ * @var string
16
+ */
17
+ protected $alias;
18
+
19
+ /**
20
+ * @var mixed
21
+ */
22
+ protected $concrete;
23
+
24
+ /**
25
+ * @var array
26
+ */
27
+ protected $arguments = [];
28
+
29
+ /**
30
+ * Constructor.
31
+ *
32
+ * @param string $alias
33
+ * @param mixed $concrete
34
+ */
35
+ public function __construct($alias, $concrete)
36
+ {
37
+ $this->alias = $alias;
38
+ $this->concrete = $concrete;
39
+ }
40
+
41
+ /**
42
+ * {@inheritdoc}
43
+ */
44
+ public function withArgument($arg)
45
+ {
46
+ $this->arguments[] = $arg;
47
+
48
+ return $this;
49
+ }
50
+
51
+ /**
52
+ * {@inheritdoc}
53
+ */
54
+ public function withArguments(array $args)
55
+ {
56
+ foreach ($args as $arg) {
57
+ $this->withArgument($arg);
58
+ }
59
+
60
+ return $this;
61
+ }
62
+ }
src/Dependencies/League/Container/Definition/CallableDefinition.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
-
5
- class CallableDefinition extends AbstractDefinition
6
- {
7
- /**
8
- * {@inheritdoc}
9
- */
10
- public function build(array $args = [])
11
- {
12
- $args = (empty($args)) ? $this->arguments : $args;
13
- $resolved = $this->resolveArguments($args);
14
-
15
- if (is_array($this->concrete) && is_string($this->concrete[0])) {
16
- $this->concrete[0] = ($this->getContainer()->has($this->concrete[0]))
17
- ? $this->getContainer()->get($this->concrete[0])
18
- : $this->concrete[0];
19
- }
20
-
21
- return call_user_func_array($this->concrete, $resolved);
22
- }
23
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
+
5
+ class CallableDefinition extends AbstractDefinition
6
+ {
7
+ /**
8
+ * {@inheritdoc}
9
+ */
10
+ public function build(array $args = [])
11
+ {
12
+ $args = (empty($args)) ? $this->arguments : $args;
13
+ $resolved = $this->resolveArguments($args);
14
+
15
+ if (is_array($this->concrete) && is_string($this->concrete[0])) {
16
+ $this->concrete[0] = ($this->getContainer()->has($this->concrete[0]))
17
+ ? $this->getContainer()->get($this->concrete[0])
18
+ : $this->concrete[0];
19
+ }
20
+
21
+ return call_user_func_array($this->concrete, $resolved);
22
+ }
23
+ }
src/Dependencies/League/Container/Definition/ClassDefinition.php CHANGED
@@ -1,67 +1,67 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
-
5
- use ReflectionClass;
6
-
7
- class ClassDefinition extends AbstractDefinition implements ClassDefinitionInterface
8
- {
9
- /**
10
- * @var array
11
- */
12
- protected $methods = [];
13
-
14
- /**
15
- * {@inheritdoc}
16
- */
17
- public function withMethodCall($method, array $args = [])
18
- {
19
- $this->methods[] = [
20
- 'method' => $method,
21
- 'arguments' => $args
22
- ];
23
-
24
- return $this;
25
- }
26
-
27
- /**
28
- * {@inheritdoc}
29
- */
30
- public function withMethodCalls(array $methods = [])
31
- {
32
- foreach ($methods as $method => $args) {
33
- $this->withMethodCall($method, $args);
34
- }
35
-
36
- return $this;
37
- }
38
-
39
- /**
40
- * {@inheritdoc}
41
- */
42
- public function build(array $args = [])
43
- {
44
- $args = (empty($args)) ? $this->arguments : $args;
45
- $resolved = $this->resolveArguments($args);
46
- $reflection = new ReflectionClass($this->concrete);
47
- $instance = $reflection->newInstanceArgs($resolved);
48
-
49
- return $this->invokeMethods($instance);
50
- }
51
-
52
- /**
53
- * Invoke methods on resolved instance.
54
- *
55
- * @param object $instance
56
- * @return object
57
- */
58
- protected function invokeMethods($instance)
59
- {
60
- foreach ($this->methods as $method) {
61
- $args = $this->resolveArguments($method['arguments']);
62
- call_user_func_array([$instance, $method['method']], $args);
63
- }
64
-
65
- return $instance;
66
- }
67
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
+
5
+ use ReflectionClass;
6
+
7
+ class ClassDefinition extends AbstractDefinition implements ClassDefinitionInterface
8
+ {
9
+ /**
10
+ * @var array
11
+ */
12
+ protected $methods = [];
13
+
14
+ /**
15
+ * {@inheritdoc}
16
+ */
17
+ public function withMethodCall($method, array $args = [])
18
+ {
19
+ $this->methods[] = [
20
+ 'method' => $method,
21
+ 'arguments' => $args
22
+ ];
23
+
24
+ return $this;
25
+ }
26
+
27
+ /**
28
+ * {@inheritdoc}
29
+ */
30
+ public function withMethodCalls(array $methods = [])
31
+ {
32
+ foreach ($methods as $method => $args) {
33
+ $this->withMethodCall($method, $args);
34
+ }
35
+
36
+ return $this;
37
+ }
38
+
39
+ /**
40
+ * {@inheritdoc}
41
+ */
42
+ public function build(array $args = [])
43
+ {
44
+ $args = (empty($args)) ? $this->arguments : $args;
45
+ $resolved = $this->resolveArguments($args);
46
+ $reflection = new ReflectionClass($this->concrete);
47
+ $instance = $reflection->newInstanceArgs($resolved);
48
+
49
+ return $this->invokeMethods($instance);
50
+ }
51
+
52
+ /**
53
+ * Invoke methods on resolved instance.
54
+ *
55
+ * @param object $instance
56
+ * @return object
57
+ */
58
+ protected function invokeMethods($instance)
59
+ {
60
+ foreach ($this->methods as $method) {
61
+ $args = $this->resolveArguments($method['arguments']);
62
+ call_user_func_array([$instance, $method['method']], $args);
63
+ }
64
+
65
+ return $instance;
66
+ }
67
+ }
src/Dependencies/League/Container/Definition/ClassDefinitionInterface.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
-
5
- interface ClassDefinitionInterface extends DefinitionInterface
6
- {
7
- /**
8
- * Add a method to be invoked
9
- *
10
- * @param string $method
11
- * @param array $args
12
- * @return $this
13
- */
14
- public function withMethodCall($method, array $args = []);
15
-
16
- /**
17
- * Add multiple methods to be invoked
18
- *
19
- * @param array $methods
20
- * @return $this
21
- */
22
- public function withMethodCalls(array $methods = []);
23
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
+
5
+ interface ClassDefinitionInterface extends DefinitionInterface
6
+ {
7
+ /**
8
+ * Add a method to be invoked
9
+ *
10
+ * @param string $method
11
+ * @param array $args
12
+ * @return $this
13
+ */
14
+ public function withMethodCall($method, array $args = []);
15
+
16
+ /**
17
+ * Add multiple methods to be invoked
18
+ *
19
+ * @param array $methods
20
+ * @return $this
21
+ */
22
+ public function withMethodCalls(array $methods = []);
23
+ }
src/Dependencies/League/Container/Definition/DefinitionFactory.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareTrait;
6
-
7
- class DefinitionFactory implements DefinitionFactoryInterface
8
- {
9
- use ImmutableContainerAwareTrait;
10
-
11
- /**
12
- * {@inheritdoc}
13
- */
14
- public function getDefinition($alias, $concrete)
15
- {
16
- if (is_callable($concrete)) {
17
- return (new CallableDefinition($alias, $concrete))->setContainer($this->getContainer());
18
- }
19
-
20
- if (is_string($concrete) && class_exists($concrete)) {
21
- return (new ClassDefinition($alias, $concrete))->setContainer($this->getContainer());
22
- }
23
-
24
- // if the item is not definable we just return the value to be stored
25
- // in the container as an arbitrary value/instance
26
- return $concrete;
27
- }
28
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareTrait;
6
+
7
+ class DefinitionFactory implements DefinitionFactoryInterface
8
+ {
9
+ use ImmutableContainerAwareTrait;
10
+
11
+ /**
12
+ * {@inheritdoc}
13
+ */
14
+ public function getDefinition($alias, $concrete)
15
+ {
16
+ if (is_callable($concrete)) {
17
+ return (new CallableDefinition($alias, $concrete))->setContainer($this->getContainer());
18
+ }
19
+
20
+ if (is_string($concrete) && class_exists($concrete)) {
21
+ return (new ClassDefinition($alias, $concrete))->setContainer($this->getContainer());
22
+ }
23
+
24
+ // if the item is not definable we just return the value to be stored
25
+ // in the container as an arbitrary value/instance
26
+ return $concrete;
27
+ }
28
+ }
src/Dependencies/League/Container/Definition/DefinitionFactoryInterface.php CHANGED
@@ -1,17 +1,17 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareInterface;
6
-
7
- interface DefinitionFactoryInterface extends ImmutableContainerAwareInterface
8
- {
9
- /**
10
- * Return a definition based on type of concrete.
11
- *
12
- * @param string $alias
13
- * @param mixed $concrete
14
- * @return mixed
15
- */
16
- public function getDefinition($alias, $concrete);
17
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareInterface;
6
+
7
+ interface DefinitionFactoryInterface extends ImmutableContainerAwareInterface
8
+ {
9
+ /**
10
+ * Return a definition based on type of concrete.
11
+ *
12
+ * @param string $alias
13
+ * @param mixed $concrete
14
+ * @return mixed
15
+ */
16
+ public function getDefinition($alias, $concrete);
17
+ }
src/Dependencies/League/Container/Definition/DefinitionInterface.php CHANGED
@@ -1,30 +1,30 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
-
5
- interface DefinitionInterface
6
- {
7
- /**
8
- * Handle instantiation and manipulation of value and return.
9
- *
10
- * @param array $args
11
- * @return mixed
12
- */
13
- public function build(array $args = []);
14
-
15
- /**
16
- * Add an argument to be injected.
17
- *
18
- * @param mixed $arg
19
- * @return $this
20
- */
21
- public function withArgument($arg);
22
-
23
- /**
24
- * Add multiple arguments to be injected.
25
- *
26
- * @param array $args
27
- * @return $this
28
- */
29
- public function withArguments(array $args);
30
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Definition;
4
+
5
+ interface DefinitionInterface
6
+ {
7
+ /**
8
+ * Handle instantiation and manipulation of value and return.
9
+ *
10
+ * @param array $args
11
+ * @return mixed
12
+ */
13
+ public function build(array $args = []);
14
+
15
+ /**
16
+ * Add an argument to be injected.
17
+ *
18
+ * @param mixed $arg
19
+ * @return $this
20
+ */
21
+ public function withArgument($arg);
22
+
23
+ /**
24
+ * Add multiple arguments to be injected.
25
+ *
26
+ * @param array $args
27
+ * @return $this
28
+ */
29
+ public function withArguments(array $args);
30
+ }
src/Dependencies/League/Container/Exception/NotFoundException.php CHANGED
@@ -1,10 +1,10 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Exception;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\Interop\Container\Exception\NotFoundException as NotFoundExceptionInterface;
6
- use InvalidArgumentException;
7
-
8
- class NotFoundException extends InvalidArgumentException implements NotFoundExceptionInterface
9
- {
10
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Exception;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\Interop\Container\Exception\NotFoundException as NotFoundExceptionInterface;
6
+ use InvalidArgumentException;
7
+
8
+ class NotFoundException extends InvalidArgumentException implements NotFoundExceptionInterface
9
+ {
10
+ }
src/Dependencies/League/Container/ImmutableContainerAwareInterface.php CHANGED
@@ -1,22 +1,22 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface as InteropContainerInterface;
6
-
7
- interface ImmutableContainerAwareInterface
8
- {
9
- /**
10
- * Set a container
11
- *
12
- * @param \RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface $container
13
- */
14
- public function setContainer(InteropContainerInterface $container);
15
-
16
- /**
17
- * Get the container
18
- *
19
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerInterface
20
- */
21
- public function getContainer();
22
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface as InteropContainerInterface;
6
+
7
+ interface ImmutableContainerAwareInterface
8
+ {
9
+ /**
10
+ * Set a container
11
+ *
12
+ * @param \RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface $container
13
+ */
14
+ public function setContainer(InteropContainerInterface $container);
15
+
16
+ /**
17
+ * Get the container
18
+ *
19
+ * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerInterface
20
+ */
21
+ public function getContainer();
22
+ }
src/Dependencies/League/Container/ImmutableContainerAwareTrait.php CHANGED
@@ -1,36 +1,36 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface as InteropContainerInterface;
6
-
7
- trait ImmutableContainerAwareTrait
8
- {
9
- /**
10
- * @var \RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface
11
- */
12
- protected $container;
13
-
14
- /**
15
- * Set a container.
16
- *
17
- * @param \RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface $container
18
- * @return $this
19
- */
20
- public function setContainer(InteropContainerInterface $container)
21
- {
22
- $this->container = $container;
23
-
24
- return $this;
25
- }
26
-
27
- /**
28
- * Get the container.
29
- *
30
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerInterface
31
- */
32
- public function getContainer()
33
- {
34
- return $this->container;
35
- }
36
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface as InteropContainerInterface;
6
+
7
+ trait ImmutableContainerAwareTrait
8
+ {
9
+ /**
10
+ * @var \RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface
11
+ */
12
+ protected $container;
13
+
14
+ /**
15
+ * Set a container.
16
+ *
17
+ * @param \RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface $container
18
+ * @return $this
19
+ */
20
+ public function setContainer(InteropContainerInterface $container)
21
+ {
22
+ $this->container = $container;
23
+
24
+ return $this;
25
+ }
26
+
27
+ /**
28
+ * Get the container.
29
+ *
30
+ * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerInterface
31
+ */
32
+ public function getContainer()
33
+ {
34
+ return $this->container;
35
+ }
36
+ }
src/Dependencies/League/Container/ImmutableContainerInterface.php CHANGED
@@ -1,10 +1,10 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface as InteropContainerInterface;
6
-
7
- interface ImmutableContainerInterface extends InteropContainerInterface
8
- {
9
-
10
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface as InteropContainerInterface;
6
+
7
+ interface ImmutableContainerInterface extends InteropContainerInterface
8
+ {
9
+
10
+ }
src/Dependencies/League/Container/Inflector/Inflector.php CHANGED
@@ -1,103 +1,103 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Inflector;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareTrait;
6
- use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\ArgumentResolverInterface;
7
- use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\ArgumentResolverTrait;
8
-
9
- class Inflector implements ArgumentResolverInterface
10
- {
11
- use ArgumentResolverTrait;
12
- use ImmutableContainerAwareTrait;
13
-
14
- /**
15
- * @var array
16
- */
17
- protected $methods = [];
18
-
19
- /**
20
- * @var array
21
- */
22
- protected $properties = [];
23
-
24
- /**
25
- * Defines a method to be invoked on the subject object.
26
- *
27
- * @param string $name
28
- * @param array $args
29
- * @return $this
30
- */
31
- public function invokeMethod($name, array $args)
32
- {
33
- $this->methods[$name] = $args;
34
-
35
- return $this;
36
- }
37
-
38
- /**
39
- * Defines multiple methods to be invoked on the subject object.
40
- *
41
- * @param array $methods
42
- * @return $this
43
- */
44
- public function invokeMethods(array $methods)
45
- {
46
- foreach ($methods as $name => $args) {
47
- $this->invokeMethod($name, $args);
48
- }
49
-
50
- return $this;
51
- }
52
-
53
- /**
54
- * Defines a property to be set on the subject object.
55
- *
56
- * @param string $property
57
- * @param mixed $value
58
- * @return $this
59
- */
60
- public function setProperty($property, $value)
61
- {
62
- $this->properties[$property] = $value;
63
-
64
- return $this;
65
- }
66
-
67
- /**
68
- * Defines multiple properties to be set on the subject object.
69
- *
70
- * @param array $properties
71
- * @return $this
72
- */
73
- public function setProperties(array $properties)
74
- {
75
- foreach ($properties as $property => $value) {
76
- $this->setProperty($property, $value);
77
- }
78
-
79
- return $this;
80
- }
81
-
82
- /**
83
- * Apply inflections to an object.
84
- *
85
- * @param object $object
86
- * @return void
87
- */
88
- public function inflect($object)
89
- {
90
- $properties = $this->resolveArguments(array_values($this->properties));
91
- $properties = array_combine(array_keys($this->properties), $properties);
92
-
93
- foreach ($properties as $property => $value) {
94
- $object->{$property} = $value;
95
- }
96
-
97
- foreach ($this->methods as $method => $args) {
98
- $args = $this->resolveArguments($args);
99
-
100
- call_user_func_array([$object, $method], $args);
101
- }
102
- }
103
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Inflector;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareTrait;
6
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\ArgumentResolverInterface;
7
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\ArgumentResolverTrait;
8
+
9
+ class Inflector implements ArgumentResolverInterface
10
+ {
11
+ use ArgumentResolverTrait;
12
+ use ImmutableContainerAwareTrait;
13
+
14
+ /**
15
+ * @var array
16
+ */
17
+ protected $methods = [];
18
+
19
+ /**
20
+ * @var array
21
+ */
22
+ protected $properties = [];
23
+
24
+ /**
25
+ * Defines a method to be invoked on the subject object.
26
+ *
27
+ * @param string $name
28
+ * @param array $args
29
+ * @return $this
30
+ */
31
+ public function invokeMethod($name, array $args)
32
+ {
33
+ $this->methods[$name] = $args;
34
+
35
+ return $this;
36
+ }
37
+
38
+ /**
39
+ * Defines multiple methods to be invoked on the subject object.
40
+ *
41
+ * @param array $methods
42
+ * @return $this
43
+ */
44
+ public function invokeMethods(array $methods)
45
+ {
46
+ foreach ($methods as $name => $args) {
47
+ $this->invokeMethod($name, $args);
48
+ }
49
+
50
+ return $this;
51
+ }
52
+
53
+ /**
54
+ * Defines a property to be set on the subject object.
55
+ *
56
+ * @param string $property
57
+ * @param mixed $value
58
+ * @return $this
59
+ */
60
+ public function setProperty($property, $value)
61
+ {
62
+ $this->properties[$property] = $value;
63
+
64
+ return $this;
65
+ }
66
+
67
+ /**
68
+ * Defines multiple properties to be set on the subject object.
69
+ *
70
+ * @param array $properties
71
+ * @return $this
72
+ */
73
+ public function setProperties(array $properties)
74
+ {
75
+ foreach ($properties as $property => $value) {
76
+ $this->setProperty($property, $value);
77
+ }
78
+
79
+ return $this;
80
+ }
81
+
82
+ /**
83
+ * Apply inflections to an object.
84
+ *
85
+ * @param object $object
86
+ * @return void
87
+ */
88
+ public function inflect($object)
89
+ {
90
+ $properties = $this->resolveArguments(array_values($this->properties));
91
+ $properties = array_combine(array_keys($this->properties), $properties);
92
+
93
+ foreach ($properties as $property => $value) {
94
+ $object->{$property} = $value;
95
+ }
96
+
97
+ foreach ($this->methods as $method => $args) {
98
+ $args = $this->resolveArguments($args);
99
+
100
+ call_user_func_array([$object, $method], $args);
101
+ }
102
+ }
103
+ }
src/Dependencies/League/Container/Inflector/InflectorAggregate.php CHANGED
@@ -1,53 +1,53 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Inflector;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareTrait;
6
-
7
- class InflectorAggregate implements InflectorAggregateInterface
8
- {
9
- use ImmutableContainerAwareTrait;
10
-
11
- /**
12
- * @var array
13
- */
14
- protected $inflectors = [];
15
-
16
- /**
17
- * {@inheritdoc}
18
- */
19
- public function add($type, callable $callback = null)
20
- {
21
- if (is_null($callback)) {
22
- $inflector = new Inflector;
23
- $this->inflectors[$type] = $inflector;
24
-
25
- return $inflector;
26
- }
27
-
28
- $this->inflectors[$type] = $callback;
29
- }
30
-
31
- /**
32
- * {@inheritdoc}
33
- */
34
- public function inflect($object)
35
- {
36
- foreach ($this->inflectors as $type => $inflector) {
37
- if (! $object instanceof $type) {
38
- continue;
39
- }
40
-
41
- if ($inflector instanceof Inflector) {
42
- $inflector->setContainer($this->getContainer());
43
- $inflector->inflect($object);
44
- continue;
45
- }
46
-
47
- // must be dealing with a callable as the inflector
48
- call_user_func_array($inflector, [$object]);
49
- }
50
-
51
- return $object;
52
- }
53
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Inflector;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareTrait;
6
+
7
+ class InflectorAggregate implements InflectorAggregateInterface
8
+ {
9
+ use ImmutableContainerAwareTrait;
10
+
11
+ /**
12
+ * @var array
13
+ */
14
+ protected $inflectors = [];
15
+
16
+ /**
17
+ * {@inheritdoc}
18
+ */
19
+ public function add($type, callable $callback = null)
20
+ {
21
+ if (is_null($callback)) {
22
+ $inflector = new Inflector;
23
+ $this->inflectors[$type] = $inflector;
24
+
25
+ return $inflector;
26
+ }
27
+
28
+ $this->inflectors[$type] = $callback;
29
+ }
30
+
31
+ /**
32
+ * {@inheritdoc}
33
+ */
34
+ public function inflect($object)
35
+ {
36
+ foreach ($this->inflectors as $type => $inflector) {
37
+ if (! $object instanceof $type) {
38
+ continue;
39
+ }
40
+
41
+ if ($inflector instanceof Inflector) {
42
+ $inflector->setContainer($this->getContainer());
43
+ $inflector->inflect($object);
44
+ continue;
45
+ }
46
+
47
+ // must be dealing with a callable as the inflector
48
+ call_user_func_array($inflector, [$object]);
49
+ }
50
+
51
+ return $object;
52
+ }
53
+ }
src/Dependencies/League/Container/Inflector/InflectorAggregateInterface.php CHANGED
@@ -1,25 +1,25 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\Inflector;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareInterface;
6
-
7
- interface InflectorAggregateInterface extends ImmutableContainerAwareInterface
8
- {
9
- /**
10
- * Add an inflector to the aggregate.
11
- *
12
- * @param string $type
13
- * @param callable $callback
14
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\Inflector\Inflector
15
- */
16
- public function add($type, callable $callback = null);
17
-
18
- /**
19
- * Applies all inflectors to an object.
20
- *
21
- * @param object $object
22
- * @return object
23
- */
24
- public function inflect($object);
25
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\Inflector;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerAwareInterface;
6
+
7
+ interface InflectorAggregateInterface extends ImmutableContainerAwareInterface
8
+ {
9
+ /**
10
+ * Add an inflector to the aggregate.
11
+ *
12
+ * @param string $type
13
+ * @param callable $callback
14
+ * @return \RocketLazyLoadPlugin\Dependencies\League\Container\Inflector\Inflector
15
+ */
16
+ public function add($type, callable $callback = null);
17
+
18
+ /**
19
+ * Applies all inflectors to an object.
20
+ *
21
+ * @param object $object
22
+ * @return object
23
+ */
24
+ public function inflect($object);
25
+ }
src/Dependencies/League/Container/ReflectionContainer.php CHANGED
@@ -1,87 +1,87 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\ArgumentResolverInterface;
6
- use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\ArgumentResolverTrait;
7
- use RocketLazyLoadPlugin\Dependencies\League\Container\Exception\NotFoundException;
8
- use ReflectionClass;
9
- use ReflectionFunction;
10
- use ReflectionMethod;
11
-
12
- class ReflectionContainer implements
13
- ArgumentResolverInterface,
14
- ImmutableContainerInterface
15
- {
16
- use ArgumentResolverTrait;
17
- use ImmutableContainerAwareTrait;
18
-
19
- /**
20
- * {@inheritdoc}
21
- */
22
- public function get($alias, array $args = [])
23
- {
24
- if (! $this->has($alias)) {
25
- throw new NotFoundException(
26
- sprintf('Alias (%s) is not an existing class and therefore cannot be resolved', $alias)
27
- );
28
- }
29
-
30
- $reflector = new ReflectionClass($alias);
31
- $construct = $reflector->getConstructor();
32
-
33
- if ($construct === null) {
34
- return new $alias;
35
- }
36
-
37
- return $reflector->newInstanceArgs(
38
- $this->reflectArguments($construct, $args)
39
- );
40
- }
41
-
42
- /**
43
- * {@inheritdoc}
44
- */
45
- public function has($alias)
46
- {
47
- return class_exists($alias);
48
- }
49
-
50
- /**
51
- * Invoke a callable via the container.
52
- *
53
- * @param callable $callable
54
- * @param array $args
55
- * @return mixed
56
- */
57
- public function call(callable $callable, array $args = [])
58
- {
59
- if (is_string($callable) && strpos($callable, '::') !== false) {
60
- $callable = explode('::', $callable);
61
- }
62
-
63
- if (is_array($callable)) {
64
- if (is_string($callable[0])) {
65
- $callable[0] = $this->getContainer()->get($callable[0]);
66
- }
67
-
68
- $reflection = new ReflectionMethod($callable[0], $callable[1]);
69
-
70
- if ($reflection->isStatic()) {
71
- $callable[0] = null;
72
- }
73
-
74
- return $reflection->invokeArgs($callable[0], $this->reflectArguments($reflection, $args));
75
- }
76
-
77
- if (is_object($callable)) {
78
- $reflection = new ReflectionMethod($callable, '__invoke');
79
-
80
- return $reflection->invokeArgs($callable, $this->reflectArguments($reflection, $args));
81
- }
82
-
83
- $reflection = new ReflectionFunction($callable);
84
-
85
- return $reflection->invokeArgs($this->reflectArguments($reflection, $args));
86
- }
87
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\ArgumentResolverInterface;
6
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Argument\ArgumentResolverTrait;
7
+ use RocketLazyLoadPlugin\Dependencies\League\Container\Exception\NotFoundException;
8
+ use ReflectionClass;
9
+ use ReflectionFunction;
10
+ use ReflectionMethod;
11
+
12
+ class ReflectionContainer implements
13
+ ArgumentResolverInterface,
14
+ ImmutableContainerInterface
15
+ {
16
+ use ArgumentResolverTrait;
17
+ use ImmutableContainerAwareTrait;
18
+
19
+ /**
20
+ * {@inheritdoc}
21
+ */
22
+ public function get($alias, array $args = [])
23
+ {
24
+ if (! $this->has($alias)) {
25
+ throw new NotFoundException(
26
+ sprintf('Alias (%s) is not an existing class and therefore cannot be resolved', $alias)
27
+ );
28
+ }
29
+
30
+ $reflector = new ReflectionClass($alias);
31
+ $construct = $reflector->getConstructor();
32
+
33
+ if ($construct === null) {
34
+ return new $alias;
35
+ }
36
+
37
+ return $reflector->newInstanceArgs(
38
+ $this->reflectArguments($construct, $args)
39
+ );
40
+ }
41
+
42
+ /**
43
+ * {@inheritdoc}
44
+ */
45
+ public function has($alias)
46
+ {
47
+ return class_exists($alias);
48
+ }
49
+
50
+ /**
51
+ * Invoke a callable via the container.
52
+ *
53
+ * @param callable $callable
54
+ * @param array $args
55
+ * @return mixed
56
+ */
57
+ public function call(callable $callable, array $args = [])
58
+ {
59
+ if (is_string($callable) && strpos($callable, '::') !== false) {
60
+ $callable = explode('::', $callable);
61
+ }
62
+
63
+ if (is_array($callable)) {
64
+ if (is_string($callable[0])) {
65
+ $callable[0] = $this->getContainer()->get($callable[0]);
66
+ }
67
+
68
+ $reflection = new ReflectionMethod($callable[0], $callable[1]);
69
+
70
+ if ($reflection->isStatic()) {
71
+ $callable[0] = null;
72
+ }
73
+
74
+ return $reflection->invokeArgs($callable[0], $this->reflectArguments($reflection, $args));
75
+ }
76
+
77
+ if (is_object($callable)) {
78
+ $reflection = new ReflectionMethod($callable, '__invoke');
79
+
80
+ return $reflection->invokeArgs($callable, $this->reflectArguments($reflection, $args));
81
+ }
82
+
83
+ $reflection = new ReflectionFunction($callable);
84
+
85
+ return $reflection->invokeArgs($this->reflectArguments($reflection, $args));
86
+ }
87
+ }
src/Dependencies/League/Container/ServiceProvider/AbstractServiceProvider.php CHANGED
@@ -1,27 +1,27 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\ContainerAwareTrait;
6
-
7
- abstract class AbstractServiceProvider implements ServiceProviderInterface
8
- {
9
- use ContainerAwareTrait;
10
-
11
- /**
12
- * @var array
13
- */
14
- protected $provides = [];
15
-
16
- /**
17
- * {@inheritdoc}
18
- */
19
- public function provides($alias = null)
20
- {
21
- if (! is_null($alias)) {
22
- return (in_array($alias, $this->provides));
23
- }
24
-
25
- return $this->provides;
26
- }
27
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ContainerAwareTrait;
6
+
7
+ abstract class AbstractServiceProvider implements ServiceProviderInterface
8
+ {
9
+ use ContainerAwareTrait;
10
+
11
+ /**
12
+ * @var array
13
+ */
14
+ protected $provides = [];
15
+
16
+ /**
17
+ * {@inheritdoc}
18
+ */
19
+ public function provides($alias = null)
20
+ {
21
+ if (! is_null($alias)) {
22
+ return (in_array($alias, $this->provides));
23
+ }
24
+
25
+ return $this->provides;
26
+ }
27
+ }
src/Dependencies/League/Container/ServiceProvider/AbstractSignatureServiceProvider.php CHANGED
@@ -1,31 +1,31 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
-
5
- abstract class AbstractSignatureServiceProvider
6
- extends AbstractServiceProvider
7
- implements SignatureServiceProviderInterface
8
- {
9
- /**
10
- * @var string
11
- */
12
- protected $signature;
13
-
14
- /**
15
- * {@inheritdoc}
16
- */
17
- public function withSignature($signature)
18
- {
19
- $this->signature = $signature;
20
-
21
- return $this;
22
- }
23
-
24
- /**
25
- * {@inheritdoc}
26
- */
27
- public function getSignature()
28
- {
29
- return (is_null($this->signature)) ? get_class($this) : $this->signature;
30
- }
31
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
+
5
+ abstract class AbstractSignatureServiceProvider
6
+ extends AbstractServiceProvider
7
+ implements SignatureServiceProviderInterface
8
+ {
9
+ /**
10
+ * @var string
11
+ */
12
+ protected $signature;
13
+
14
+ /**
15
+ * {@inheritdoc}
16
+ */
17
+ public function withSignature($signature)
18
+ {
19
+ $this->signature = $signature;
20
+
21
+ return $this;
22
+ }
23
+
24
+ /**
25
+ * {@inheritdoc}
26
+ */
27
+ public function getSignature()
28
+ {
29
+ return (is_null($this->signature)) ? get_class($this) : $this->signature;
30
+ }
31
+ }
src/Dependencies/League/Container/ServiceProvider/BootableServiceProviderInterface.php CHANGED
@@ -1,14 +1,14 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
-
5
- interface BootableServiceProviderInterface extends ServiceProviderInterface
6
- {
7
- /**
8
- * Method will be invoked on registration of a service provider implementing
9
- * this interface. Provides ability for eager loading of Service Providers.
10
- *
11
- * @return void
12
- */
13
- public function boot();
14
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
+
5
+ interface BootableServiceProviderInterface extends ServiceProviderInterface
6
+ {
7
+ /**
8
+ * Method will be invoked on registration of a service provider implementing
9
+ * this interface. Provides ability for eager loading of Service Providers.
10
+ *
11
+ * @return void
12
+ */
13
+ public function boot();
14
+ }
src/Dependencies/League/Container/ServiceProvider/ServiceProviderAggregate.php CHANGED
@@ -1,88 +1,88 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\ContainerAwareInterface;
6
- use RocketLazyLoadPlugin\Dependencies\League\Container\ContainerAwareTrait;
7
-
8
- class ServiceProviderAggregate implements ServiceProviderAggregateInterface
9
- {
10
- use ContainerAwareTrait;
11
-
12
- /**
13
- * @var array
14
- */
15
- protected $providers = [];
16
-
17
- /**
18
- * @var array
19
- */
20
- protected $registered = [];
21
-
22
- /**
23
- * {@inheritdoc}
24
- */
25
- public function add($provider)
26
- {
27
- if (is_string($provider) && class_exists($provider)) {
28
- $provider = new $provider;
29
- }
30
-
31
- if ($provider instanceof ContainerAwareInterface) {
32
- $provider->setContainer($this->getContainer());
33
- }
34
-
35
- if ($provider instanceof BootableServiceProviderInterface) {
36
- $provider->boot();
37
- }
38
-
39
- if ($provider instanceof ServiceProviderInterface) {
40
- foreach ($provider->provides() as $service) {
41
- $this->providers[$service] = $provider;
42
- }
43
-
44
- return $this;
45
- }
46
-
47
- throw new \InvalidArgumentException(
48
- 'A service provider must be a fully qualified class name or instance ' .
49
- 'of (\RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderInterface)'
50
- );
51
- }
52
-
53
- /**
54
- * {@inheritdoc}
55
- */
56
- public function provides($service)
57
- {
58
- return array_key_exists($service, $this->providers);
59
- }
60
-
61
- /**
62
- * {@inheritdoc}
63
- */
64
- public function register($service)
65
- {
66
- if (! array_key_exists($service, $this->providers)) {
67
- throw new \InvalidArgumentException(
68
- sprintf('(%s) is not provided by a service provider', $service)
69
- );
70
- }
71
-
72
- $provider = $this->providers[$service];
73
- $signature = get_class($provider);
74
-
75
- if ($provider instanceof SignatureServiceProviderInterface) {
76
- $signature = $provider->getSignature();
77
- }
78
-
79
- // ensure that the provider hasn't already been invoked by any other service request
80
- if (in_array($signature, $this->registered)) {
81
- return;
82
- }
83
-
84
- $provider->register();
85
-
86
- $this->registered[] = $signature;
87
- }
88
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ContainerAwareInterface;
6
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ContainerAwareTrait;
7
+
8
+ class ServiceProviderAggregate implements ServiceProviderAggregateInterface
9
+ {
10
+ use ContainerAwareTrait;
11
+
12
+ /**
13
+ * @var array
14
+ */
15
+ protected $providers = [];
16
+
17
+ /**
18
+ * @var array
19
+ */
20
+ protected $registered = [];
21
+
22
+ /**
23
+ * {@inheritdoc}
24
+ */
25
+ public function add($provider)
26
+ {
27
+ if (is_string($provider) && class_exists($provider)) {
28
+ $provider = new $provider;
29
+ }
30
+
31
+ if ($provider instanceof ContainerAwareInterface) {
32
+ $provider->setContainer($this->getContainer());
33
+ }
34
+
35
+ if ($provider instanceof BootableServiceProviderInterface) {
36
+ $provider->boot();
37
+ }
38
+
39
+ if ($provider instanceof ServiceProviderInterface) {
40
+ foreach ($provider->provides() as $service) {
41
+ $this->providers[$service] = $provider;
42
+ }
43
+
44
+ return $this;
45
+ }
46
+
47
+ throw new \InvalidArgumentException(
48
+ 'A service provider must be a fully qualified class name or instance ' .
49
+ 'of (\RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderInterface)'
50
+ );
51
+ }
52
+
53
+ /**
54
+ * {@inheritdoc}
55
+ */
56
+ public function provides($service)
57
+ {
58
+ return array_key_exists($service, $this->providers);
59
+ }
60
+
61
+ /**
62
+ * {@inheritdoc}
63
+ */
64
+ public function register($service)
65
+ {
66
+ if (! array_key_exists($service, $this->providers)) {
67
+ throw new \InvalidArgumentException(
68
+ sprintf('(%s) is not provided by a service provider', $service)
69
+ );
70
+ }
71
+
72
+ $provider = $this->providers[$service];
73
+ $signature = get_class($provider);
74
+
75
+ if ($provider instanceof SignatureServiceProviderInterface) {
76
+ $signature = $provider->getSignature();
77
+ }
78
+
79
+ // ensure that the provider hasn't already been invoked by any other service request
80
+ if (in_array($signature, $this->registered)) {
81
+ return;
82
+ }
83
+
84
+ $provider->register();
85
+
86
+ $this->registered[] = $signature;
87
+ }
88
+ }
src/Dependencies/League/Container/ServiceProvider/ServiceProviderAggregateInterface.php CHANGED
@@ -1,32 +1,32 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\ContainerAwareInterface;
6
-
7
- interface ServiceProviderAggregateInterface extends ContainerAwareInterface
8
- {
9
- /**
10
- * Add a service provider to the aggregate.
11
- *
12
- * @param string|\RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderInterface $provider
13
- * @return $this
14
- */
15
- public function add($provider);
16
-
17
- /**
18
- * Determines whether a service is provided by the aggregate.
19
- *
20
- * @param string $service
21
- * @return boolean
22
- */
23
- public function provides($service);
24
-
25
- /**
26
- * Invokes the register method of a provider that provides a specific service.
27
- *
28
- * @param string $service
29
- * @return void
30
- */
31
- public function register($service);
32
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ContainerAwareInterface;
6
+
7
+ interface ServiceProviderAggregateInterface extends ContainerAwareInterface
8
+ {
9
+ /**
10
+ * Add a service provider to the aggregate.
11
+ *
12
+ * @param string|\RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderInterface $provider
13
+ * @return $this
14
+ */
15
+ public function add($provider);
16
+
17
+ /**
18
+ * Determines whether a service is provided by the aggregate.
19
+ *
20
+ * @param string $service
21
+ * @return boolean
22
+ */
23
+ public function provides($service);
24
+
25
+ /**
26
+ * Invokes the register method of a provider that provides a specific service.
27
+ *
28
+ * @param string $service
29
+ * @return void
30
+ */
31
+ public function register($service);
32
+ }
src/Dependencies/League/Container/ServiceProvider/ServiceProviderInterface.php CHANGED
@@ -1,26 +1,26 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
-
5
- use RocketLazyLoadPlugin\Dependencies\League\Container\ContainerAwareInterface;
6
-
7
- interface ServiceProviderInterface extends ContainerAwareInterface
8
- {
9
- /**
10
- * Returns a boolean if checking whether this provider provides a specific
11
- * service or returns an array of provided services if no argument passed.
12
- *
13
- * @param string $service
14
- * @return boolean|array
15
- */
16
- public function provides($service = null);
17
-
18
- /**
19
- * Use the register method to register items with the container via the
20
- * protected $this->container property or the `getContainer` method
21
- * from the ContainerAwareTrait.
22
- *
23
- * @return void
24
- */
25
- public function register();
26
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
+
5
+ use RocketLazyLoadPlugin\Dependencies\League\Container\ContainerAwareInterface;
6
+
7
+ interface ServiceProviderInterface extends ContainerAwareInterface
8
+ {
9
+ /**
10
+ * Returns a boolean if checking whether this provider provides a specific
11
+ * service or returns an array of provided services if no argument passed.
12
+ *
13
+ * @param string $service
14
+ * @return boolean|array
15
+ */
16
+ public function provides($service = null);
17
+
18
+ /**
19
+ * Use the register method to register items with the container via the
20
+ * protected $this->container property or the `getContainer` method
21
+ * from the ContainerAwareTrait.
22
+ *
23
+ * @return void
24
+ */
25
+ public function register();
26
+ }
src/Dependencies/League/Container/ServiceProvider/SignatureServiceProviderInterface.php CHANGED
@@ -1,24 +1,24 @@
1
- <?php
2
-
3
- namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
-
5
- interface SignatureServiceProviderInterface
6
- {
7
- /**
8
- * Set a custom signature for the service provider. This enables
9
- * registering the same service provider multiple times.
10
- *
11
- * @param string $signature
12
- * @return self
13
- */
14
- public function withSignature($signature);
15
-
16
- /**
17
- * The signature of the service provider uniquely identifies it, so
18
- * that we can quickly determine if it has already been registered.
19
- * Defaults to get_class($provider).
20
- *
21
- * @return string
22
- */
23
- public function getSignature();
24
- }
1
+ <?php
2
+
3
+ namespace RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider;
4
+
5
+ interface SignatureServiceProviderInterface
6
+ {
7
+ /**
8
+ * Set a custom signature for the service provider. This enables
9
+ * registering the same service provider multiple times.
10
+ *
11
+ * @param string $signature
12
+ * @return self
13
+ */
14
+ public function withSignature($signature);
15
+
16
+ /**
17
+ * The signature of the service provider uniquely identifies it, so
18
+ * that we can quickly determine if it has already been registered.
19
+ * Defaults to get_class($provider).
20
+ *
21
+ * @return string
22
+ */
23
+ public function getSignature();
24
+ }
src/Dependencies/Psr/Container/ContainerExceptionInterface.php CHANGED
@@ -1,13 +1,13 @@
1
- <?php
2
- /**
3
- * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
4
- */
5
-
6
- namespace RocketLazyLoadPlugin\Dependencies\Psr\Container;
7
-
8
- /**
9
- * Base interface representing a generic exception in a container.
10
- */
11
- interface ContainerExceptionInterface
12
- {
13
- }
1
+ <?php
2
+ /**
3
+ * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
4
+ */
5
+
6
+ namespace RocketLazyLoadPlugin\Dependencies\Psr\Container;
7
+
8
+ /**
9
+ * Base interface representing a generic exception in a container.
10
+ */
11
+ interface ContainerExceptionInterface
12
+ {
13
+ }
src/Dependencies/Psr/Container/ContainerInterface.php CHANGED
@@ -1,37 +1,37 @@
1
- <?php
2
- /**
3
- * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
4
- */
5
-
6
- namespace RocketLazyLoadPlugin\Dependencies\Psr\Container;
7
-
8
- /**
9
- * Describes the interface of a container that exposes methods to read its entries.
10
- */
11
- interface ContainerInterface
12
- {
13
- /**
14
- * Finds an entry of the container by its identifier and returns it.
15
- *
16
- * @param string $id Identifier of the entry to look for.
17
- *
18
- * @throws NotFoundExceptionInterface No entry was found for **this** identifier.
19
- * @throws ContainerExceptionInterface Error while retrieving the entry.
20
- *
21
- * @return mixed Entry.
22
- */
23
- public function get($id);
24
-
25
- /**
26
- * Returns true if the container can return an entry for the given identifier.
27
- * Returns false otherwise.
28
- *
29
- * `has($id)` returning true does not mean that `get($id)` will not throw an exception.
30
- * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
31
- *
32
- * @param string $id Identifier of the entry to look for.
33
- *
34
- * @return bool
35
- */
36
- public function has($id);
37
- }
1
+ <?php
2
+ /**
3
+ * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
4
+ */
5
+
6
+ namespace RocketLazyLoadPlugin\Dependencies\Psr\Container;
7
+
8
+ /**
9
+ * Describes the interface of a container that exposes methods to read its entries.
10
+ */
11
+ interface ContainerInterface
12
+ {
13
+ /**
14
+ * Finds an entry of the container by its identifier and returns it.
15
+ *
16
+ * @param string $id Identifier of the entry to look for.
17
+ *
18
+ * @throws NotFoundExceptionInterface No entry was found for **this** identifier.
19
+ * @throws ContainerExceptionInterface Error while retrieving the entry.
20
+ *
21
+ * @return mixed Entry.
22
+ */
23
+ public function get($id);
24
+
25
+ /**
26
+ * Returns true if the container can return an entry for the given identifier.
27
+ * Returns false otherwise.
28
+ *
29
+ * `has($id)` returning true does not mean that `get($id)` will not throw an exception.
30
+ * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
31
+ *
32
+ * @param string $id Identifier of the entry to look for.
33
+ *
34
+ * @return bool
35
+ */
36
+ public function has($id);
37
+ }
src/Dependencies/Psr/Container/NotFoundExceptionInterface.php CHANGED
@@ -1,13 +1,13 @@
1
- <?php
2
- /**
3
- * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
4
- */
5
-
6
- namespace RocketLazyLoadPlugin\Dependencies\Psr\Container;
7
-
8
- /**
9
- * No entry was found in the container.
10
- */
11
- interface NotFoundExceptionInterface extends ContainerExceptionInterface
12
- {
13
- }
1
+ <?php
2
+ /**
3
+ * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
4
+ */
5
+
6
+ namespace RocketLazyLoadPlugin\Dependencies\Psr\Container;
7
+
8
+ /**
9
+ * No entry was found in the container.
10
+ */
11
+ interface NotFoundExceptionInterface extends ContainerExceptionInterface
12
+ {
13
+ }
src/Dependencies/RocketLazyload/Assets.php CHANGED
@@ -1,299 +1,299 @@
1
- <?php
2
- /**
3
- * Handle the lazyload required assets: inline CSS and JS
4
- *
5
- * @package RocketLazyload
6
- */
7
-
8
- namespace RocketLazyLoadPlugin\Dependencies\RocketLazyload;
9
-
10
- /**
11
- * Class containing the methods to return or print the assets needed for lazyloading
12
- */
13
- class Assets
14
- {
15
- /**
16
- * Inserts the lazyload script in the HTML
17
- *
18
- * @param array $args Array of arguments to populate the lazyload script tag.
19
- * @return void
20
- */
21
- public function insertLazyloadScript($args = [])
22
- {
23
- echo $this->getLazyloadScript($args);
24
- }
25
-
26
- /**
27
- * Gets the inline lazyload script configuration
28
- *
29
- * @param array $args Array of arguments to populate the lazyload script options.
30
- * @return string
31
- */
32
- public function getInlineLazyloadScript($args = [])
33
- {
34
- $defaults = [
35
- 'elements' => [
36
- 'img',
37
- 'iframe',
38
- ],
39
- 'threshold' => 300,
40
- 'options' => [],
41
- ];
42
-
43
- $allowed_options = [
44
- 'container' => 1,
45
- 'thresholds' => 1,
46
- 'data_bg' => 1,
47
- 'class_error' => 1,
48
- 'load_delay' => 1,
49
- 'auto_unobserve' => 1,
50
- 'callback_enter' => 1,
51
- 'callback_exit' => 1,
52
- 'callback_reveal' => 1,
53
- 'callback_error' => 1,
54
- 'callback_finish' => 1,
55
- 'use_native' => 1,
56
- ];
57
-
58
- $args = wp_parse_args($args, $defaults);
59
- $script = '';
60
-
61
- $args['options'] = array_intersect_key($args['options'], $allowed_options);
62
-
63
- $script .= 'window.lazyLoadOptions = {
64
- elements_selector: "' . esc_attr(implode(',', $args['elements'])) . '",
65
- data_src: "lazy-src",
66
- data_srcset: "lazy-srcset",
67
- data_sizes: "lazy-sizes",
68
- class_loading: "lazyloading",
69
- class_loaded: "lazyloaded",
70
- threshold: ' . esc_attr($args['threshold']) . ',
71
- callback_loaded: function(element) {
72
- if ( element.tagName === "IFRAME" && element.dataset.rocketLazyload == "fitvidscompatible" ) {
73
- if (element.classList.contains("lazyloaded") ) {
74
- if (typeof window.jQuery != "undefined") {
75
- if (jQuery.fn.fitVids) {
76
- jQuery(element).parent().fitVids();
77
- }
78
- }
79
- }
80
- }
81
- }';
82
-
83
- if (! empty($args['options'])) {
84
- $script .= ',' . PHP_EOL;
85
-
86
- foreach ($args['options'] as $option => $value) {
87
- $script .= $option . ': ' . $value . ',';
88
- }
89
-
90
- $script = rtrim($script, ',');
91
- }
92
-
93
- $script .= '};';
94
-
95
- $script .= '
96
- window.addEventListener(\'LazyLoad::Initialized\', function (e) {
97
- var lazyLoadInstance = e.detail.instance;
98
-
99
- if (window.MutationObserver) {
100
- var observer = new MutationObserver(function(mutations) {
101
- var image_count = 0;
102
- var iframe_count = 0;
103
- var rocketlazy_count = 0;
104
-
105
- mutations.forEach(function(mutation) {
106
- for (i = 0; i < mutation.addedNodes.length; i++) {
107
- if (typeof mutation.addedNodes[i].getElementsByTagName !== \'function\') {
108
- return;
109
- }
110
-
111
- if (typeof mutation.addedNodes[i].getElementsByClassName !== \'function\') {
112
- return;
113
- }
114
-
115
- images = mutation.addedNodes[i].getElementsByTagName(\'img\');
116
- is_image = mutation.addedNodes[i].tagName == "IMG";
117
- iframes = mutation.addedNodes[i].getElementsByTagName(\'iframe\');
118
- is_iframe = mutation.addedNodes[i].tagName == "IFRAME";
119
- rocket_lazy = mutation.addedNodes[i].getElementsByClassName(\'rocket-lazyload\');
120
-
121
- image_count += images.length;
122
- iframe_count += iframes.length;
123
- rocketlazy_count += rocket_lazy.length;
124
-
125
- if(is_image){
126
- image_count += 1;
127
- }
128
-
129
- if(is_iframe){
130
- iframe_count += 1;
131
- }
132
- }
133
- } );
134
-
135
- if(image_count > 0 || iframe_count > 0 || rocketlazy_count > 0){
136
- lazyLoadInstance.update();
137
- }
138
- } );
139
-
140
- var b = document.getElementsByTagName("body")[0];
141
- var config = { childList: true, subtree: true };
142
-
143
- observer.observe(b, config);
144
- }
145
- }, false);';
146
-
147
- return $script;
148
- }
149
-
150
- /**
151
- * Returns the lazyload inline script
152
- *
153
- * @param array $args Array of arguments to populate the lazyload script options.
154
- * @return string
155
- */
156
- public function getLazyloadScript($args = [])
157
- {
158
- $defaults = [
159
- 'base_url' => '',
160
- 'version' => '',
161
- 'polyfill' => false,
162
- ];
163
-
164
- $args = wp_parse_args($args, $defaults);
165
- $min = ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) ? '' : '.min';
166
- $script = '';
167
-
168
- if (isset($args['polyfill']) && $args['polyfill']) {
169
- $script .= '<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?flags=gated&features=default%2CIntersectionObserver%2CIntersectionObserverEntry"></script>';
170
- }
171
-
172
- /**
173
- * Filters the script tag for the lazyload script
174
- *
175
- * @since 2.2.6
176
- *
177
- * @param $script_tag HTML tag for the lazyload script.
178
- */
179
- $script .= apply_filters('rocket_lazyload_script_tag', '<script data-no-minify="1" async src="' . $args['base_url'] . $args['version'] . '/lazyload' . $min . '.js"></script>');
180
-
181
- return $script;
182
- }
183
-
184
- /**
185
- * Inserts in the HTML the script to replace the Youtube thumbnail by the iframe.
186
- *
187
- * @param array $args Array of arguments to populate the script options.
188
- * @return void
189
- */
190
- public function insertYoutubeThumbnailScript($args = [])
191
- {
192
- echo $this->getYoutubeThumbnailScript($args);
193
- }
194
-
195
- /**
196
- * Returns the Youtube Thumbnail inline script
197
- *
198
- * @param array $args Array of arguments to populate the script options.
199
- * @return string
200
- */
201
- public function getYoutubeThumbnailScript($args = [])
202
- {
203
- $defaults = [
204
- 'resolution' => 'hqdefault',
205
- 'lazy_image' => false,
206
- ];
207
-
208
- $allowed_resolutions = [
209
- 'default' => [
210
- 'width' => 120,
211
- 'height' => 90,
212
- ],
213
- 'mqdefault' => [
214
- 'width' => 320,
215
- 'height' => 180,
216
- ],
217
- 'hqdefault' => [
218
- 'width' => 480,
219
- 'height' => 360,
220
- ],
221
- 'sddefault' => [
222
- 'width' => 640,
223
- 'height' => 480,
224
- ],
225
-
226
- 'maxresdefault' => [
227
- 'width' => 1280,
228
- 'height' => 720,
229
- ],
230
- ];
231
-
232
- $args['resolution'] = ( isset($args['resolution']) && isset($allowed_resolutions[ $args['resolution'] ]) ) ? $args['resolution'] : 'hqdefault';
233
-
234
- $args = wp_parse_args($args, $defaults);
235
-
236
- $image = '<img src="https://i.ytimg.com/vi/ID/' . $args['resolution'] . '.jpg" alt="" width="' . $allowed_resolutions[ $args['resolution'] ]['width'] . '" height="' . $allowed_resolutions[ $args['resolution'] ]['height'] . '">';
237
-
238
- if (isset($args['lazy_image']) && $args['lazy_image']) {
239
- $image = '<img loading="lazy" data-lazy-src="https://i.ytimg.com/vi/ID/' . $args['resolution'] . '.jpg" alt="" width="' . $allowed_resolutions[ $args['resolution'] ]['width'] . '" height="' . $allowed_resolutions[ $args['resolution'] ]['height'] . '"><noscript><img src="https://i.ytimg.com/vi/ID/' . $args['resolution'] . '.jpg" alt="" width="' . $allowed_resolutions[ $args['resolution'] ]['width'] . '" height="' . $allowed_resolutions[ $args['resolution'] ]['height'] . '"></noscript>';
240
- }
241
-
242
- return "<script>function lazyLoadThumb(e){var t='{$image}',a='<div class=\"play\"></div>';return t.replace(\"ID\",e)+a}function lazyLoadYoutubeIframe(){var e=document.createElement(\"iframe\"),t=\"https://www.youtube.com/embed/ID?autoplay=1\";t+=0===this.dataset.query.length?'':'&'+this.dataset.query;e.setAttribute(\"src\",t.replace(\"ID\",this.dataset.id)),e.setAttribute(\"frameborder\",\"0\"),e.setAttribute(\"allowfullscreen\",\"1\"),e.setAttribute(\”allow\”, \”accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\”),this.parentNode.replaceChild(e,this)}document.addEventListener(\"DOMContentLoaded\",function(){var e,t,a=document.getElementsByClassName(\"rll-youtube-player\");for(t=0;t<a.length;t++)e=document.createElement(\"div\"),e.setAttribute(\"data-id\",a[t].dataset.id),e.setAttribute(\"data-query\", a[t].dataset.query),e.innerHTML=lazyLoadThumb(a[t].dataset.id),e.onclick=lazyLoadYoutubeIframe,a[t].appendChild(e)});</script>";
243
- }
244
-
245
- /**
246
- * Inserts the CSS to style the Youtube thumbnail container
247
- *
248
- * @param array $args Array of arguments to populate the CSS.
249
- * @return void
250
- */
251
- public function insertYoutubeThumbnailCSS($args = [])
252
- {
253
- wp_register_style('rocket-lazyload', false);
254
- wp_enqueue_style('rocket-lazyload');
255
- wp_add_inline_style('rocket-lazyload', $this->getYoutubeThumbnailCSS($args));
256
- }
257
-
258
- /**
259
- * Returns the CSS for the Youtube Thumbnail
260
- *
261
- * @param array $args Array of arguments to populate the CSS.
262
- * @return string
263
- */
264
- public function getYoutubeThumbnailCSS($args = [])
265
- {
266
- $defaults = [
267
- 'base_url' => '',
268
- 'responsive_embeds' => true,
269
- ];
270
-
271
- $args = wp_parse_args($args, $defaults);
272
-
273
- $css = '.rll-youtube-player{position:relative;padding-bottom:56.23%;height:0;overflow:hidden;max-width:100%;}.rll-youtube-player iframe{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;background:0 0}.rll-youtube-player img{bottom:0;display:block;left:0;margin:auto;max-width:100%;width:100%;position:absolute;right:0;top:0;border:none;height:auto;cursor:pointer;-webkit-transition:.4s all;-moz-transition:.4s all;transition:.4s all}.rll-youtube-player img:hover{-webkit-filter:brightness(75%)}.rll-youtube-player .play{height:72px;width:72px;left:50%;top:50%;margin-left:-36px;margin-top:-36px;position:absolute;background:url(' . $args['base_url'] . 'img/youtube.png) no-repeat;cursor:pointer}';
274
-
275
- if ($args['responsive_embeds']) {
276
- $css .= '.wp-has-aspect-ratio .rll-youtube-player{position:absolute;padding-bottom:0;width:100%;height:100%;top:0;bottom:0;left:0;right:0}';
277
- }
278
-
279
- return $css;
280
- }
281
-
282
- /**
283
- * Inserts the CSS needed when Javascript is not enabled to keep the display correct
284
- */
285
- public function insertNoJSCSS()
286
- {
287
- echo $this->getNoJSCSS();
288
- }
289
-
290
- /**
291
- * Returns the CSS to correctly display images when JavaScript is disabled
292
- *
293
- * @return string
294
- */
295
- public function getNoJSCSS()
296
- {
297
- return '<noscript><style id="rocket-lazyload-nojs-css">.rll-youtube-player, [data-lazy-src]{display:none !important;}</style></noscript>';
298
- }
299
- }
1
+ <?php
2
+ /**
3
+ * Handle the lazyload required assets: inline CSS and JS
4
+ *
5
+ * @package RocketLazyload
6
+ */
7
+
8
+ namespace RocketLazyLoadPlugin\Dependencies\RocketLazyload;
9
+
10
+ /**
11
+ * Class containing the methods to return or print the assets needed for lazyloading
12
+ */
13
+ class Assets
14
+ {
15
+ /**
16
+ * Inserts the lazyload script in the HTML
17
+ *
18
+ * @param array $args Array of arguments to populate the lazyload script tag.
19
+ * @return void
20
+ */
21
+ public function insertLazyloadScript($args = [])
22
+ {
23
+ echo $this->getLazyloadScript($args);
24
+ }
25
+
26
+ /**
27
+ * Gets the inline lazyload script configuration
28
+ *
29
+ * @param array $args Array of arguments to populate the lazyload script options.
30
+ * @return string
31
+ */
32
+ public function getInlineLazyloadScript($args = [])
33
+ {
34
+ $defaults = [
35
+ 'elements' => [
36
+ 'img',
37
+ 'iframe',
38
+ ],
39
+ 'threshold' => 300,
40
+ 'options' => [],
41
+ ];
42
+
43
+ $allowed_options = [
44
+ 'container' => 1,
45
+ 'thresholds' => 1,
46
+ 'data_bg' => 1,
47
+ 'class_error' => 1,
48
+ 'load_delay' => 1,
49
+ 'auto_unobserve' => 1,
50
+ 'callback_enter' => 1,
51
+ 'callback_exit' => 1,
52
+ 'callback_reveal' => 1,
53
+ 'callback_error' => 1,
54
+ 'callback_finish' => 1,
55
+ 'use_native' => 1,
56
+ ];
57
+
58
+ $args = wp_parse_args($args, $defaults);
59
+ $script = '';
60
+
61
+ $args['options'] = array_intersect_key($args['options'], $allowed_options);
62
+
63
+ $script .= 'window.lazyLoadOptions = {
64
+ elements_selector: "' . esc_attr(implode(',', $args['elements'])) . '",
65
+ data_src: "lazy-src",
66
+ data_srcset: "lazy-srcset",
67
+ data_sizes: "lazy-sizes",
68
+ class_loading: "lazyloading",
69
+ class_loaded: "lazyloaded",
70
+ threshold: ' . esc_attr($args['threshold']) . ',
71
+ callback_loaded: function(element) {
72
+ if ( element.tagName === "IFRAME" && element.dataset.rocketLazyload == "fitvidscompatible" ) {
73
+ if (element.classList.contains("lazyloaded") ) {
74
+ if (typeof window.jQuery != "undefined") {
75
+ if (jQuery.fn.fitVids) {
76
+ jQuery(element).parent().fitVids();
77
+ }
78
+ }
79
+ }
80
+ }
81
+ }';
82
+
83
+ if (! empty($args['options'])) {
84
+ $script .= ',' . PHP_EOL;
85
+
86
+ foreach ($args['options'] as $option => $value) {
87
+ $script .= $option . ': ' . $value . ',';
88
+ }
89
+
90
+ $script = rtrim($script, ',');
91
+ }
92
+
93
+ $script .= '};';
94
+
95
+ $script .= '
96
+ window.addEventListener(\'LazyLoad::Initialized\', function (e) {
97
+ var lazyLoadInstance = e.detail.instance;
98
+
99
+ if (window.MutationObserver) {
100
+ var observer = new MutationObserver(function(mutations) {
101
+ var image_count = 0;
102
+ var iframe_count = 0;
103
+ var rocketlazy_count = 0;
104
+
105
+ mutations.forEach(function(mutation) {
106
+ for (i = 0; i < mutation.addedNodes.length; i++) {
107
+ if (typeof mutation.addedNodes[i].getElementsByTagName !== \'function\') {
108
+ return;
109
+ }
110
+
111
+ if (typeof mutation.addedNodes[i].getElementsByClassName !== \'function\') {
112
+ return;
113
+ }
114
+
115
+ images = mutation.addedNodes[i].getElementsByTagName(\'img\');
116
+ is_image = mutation.addedNodes[i].tagName == "IMG";
117
+ iframes = mutation.addedNodes[i].getElementsByTagName(\'iframe\');
118
+ is_iframe = mutation.addedNodes[i].tagName == "IFRAME";
119
+ rocket_lazy = mutation.addedNodes[i].getElementsByClassName(\'rocket-lazyload\');
120
+
121
+ image_count += images.length;
122
+ iframe_count += iframes.length;
123
+ rocketlazy_count += rocket_lazy.length;
124
+
125
+ if(is_image){
126
+ image_count += 1;
127
+ }
128
+
129
+ if(is_iframe){
130
+ iframe_count += 1;
131
+ }
132
+ }
133
+ } );
134
+
135
+ if(image_count > 0 || iframe_count > 0 || rocketlazy_count > 0){
136
+ lazyLoadInstance.update();
137
+ }
138
+ } );
139
+
140
+ var b = document.getElementsByTagName("body")[0];
141
+ var config = { childList: true, subtree: true };
142
+
143
+ observer.observe(b, config);
144
+ }
145
+ }, false);';
146
+
147
+ return $script;
148
+ }
149
+
150
+ /**
151
+ * Returns the lazyload inline script
152
+ *
153
+ * @param array $args Array of arguments to populate the lazyload script options.
154
+ * @return string
155
+ */
156
+ public function getLazyloadScript($args = [])
157
+ {
158
+ $defaults = [
159
+ 'base_url' => '',
160
+ 'version' => '',
161
+ 'polyfill' => false,
162
+ ];
163
+
164
+ $args = wp_parse_args($args, $defaults);
165
+ $min = ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) ? '' : '.min';
166
+ $script = '';
167
+
168
+ if (isset($args['polyfill']) && $args['polyfill']) {
169
+ $script .= '<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?flags=gated&features=default%2CIntersectionObserver%2CIntersectionObserverEntry"></script>';
170
+ }
171
+
172
+ /**
173
+ * Filters the script tag for the lazyload script
174
+ *
175
+ * @since 2.2.6
176
+ *
177
+ * @param $script_tag HTML tag for the lazyload script.
178
+ */
179
+ $script .= apply_filters('rocket_lazyload_script_tag', '<script data-no-minify="1" async src="' . $args['base_url'] . $args['version'] . '/lazyload' . $min . '.js"></script>');
180
+
181
+ return $script;
182
+ }
183
+
184
+ /**
185
+ * Inserts in the HTML the script to replace the Youtube thumbnail by the iframe.
186
+ *
187
+ * @param array $args Array of arguments to populate the script options.
188
+ * @return void
189
+ */
190
+ public function insertYoutubeThumbnailScript($args = [])
191
+ {
192
+ echo $this->getYoutubeThumbnailScript($args);
193
+ }
194
+
195
+ /**
196
+ * Returns the Youtube Thumbnail inline script
197
+ *
198
+ * @param array $args Array of arguments to populate the script options.
199
+ * @return string
200
+ */
201
+ public function getYoutubeThumbnailScript($args = [])
202
+ {
203
+ $defaults = [
204
+ 'resolution' => 'hqdefault',
205
+ 'lazy_image' => false,
206
+ ];
207
+
208
+ $allowed_resolutions = [
209
+ 'default' => [
210
+ 'width' => 120,
211
+ 'height' => 90,
212
+ ],
213
+ 'mqdefault' => [
214
+ 'width' => 320,
215
+ 'height' => 180,
216
+ ],
217
+ 'hqdefault' => [
218
+ 'width' => 480,
219
+ 'height' => 360,
220
+ ],
221
+ 'sddefault' => [
222
+ 'width' => 640,
223
+ 'height' => 480,
224
+ ],
225
+
226
+ 'maxresdefault' => [
227
+ 'width' => 1280,
228
+ 'height' => 720,
229
+ ],
230
+ ];
231
+
232
+ $args['resolution'] = ( isset($args['resolution']) && isset($allowed_resolutions[ $args['resolution'] ]) ) ? $args['resolution'] : 'hqdefault';
233
+
234
+ $args = wp_parse_args($args, $defaults);
235
+
236
+ $image = '<img src="https://i.ytimg.com/vi/ID/' . $args['resolution'] . '.jpg" alt="" width="' . $allowed_resolutions[ $args['resolution'] ]['width'] . '" height="' . $allowed_resolutions[ $args['resolution'] ]['height'] . '">';
237
+
238
+ if (isset($args['lazy_image']) && $args['lazy_image']) {
239
+ $image = '<img loading="lazy" data-lazy-src="https://i.ytimg.com/vi/ID/' . $args['resolution'] . '.jpg" alt="" width="' . $allowed_resolutions[ $args['resolution'] ]['width'] . '" height="' . $allowed_resolutions[ $args['resolution'] ]['height'] . '"><noscript><img src="https://i.ytimg.com/vi/ID/' . $args['resolution'] . '.jpg" alt="" width="' . $allowed_resolutions[ $args['resolution'] ]['width'] . '" height="' . $allowed_resolutions[ $args['resolution'] ]['height'] . '"></noscript>';
240
+ }
241
+
242
+ return "<script>function lazyLoadThumb(e){var t='{$image}',a='<div class=\"play\"></div>';return t.replace(\"ID\",e)+a}function lazyLoadYoutubeIframe(){var e=document.createElement(\"iframe\"),t=\"https://www.youtube.com/embed/ID?autoplay=1\";t+=0===this.dataset.query.length?'':'&'+this.dataset.query;e.setAttribute(\"src\",t.replace(\"ID\",this.dataset.id)),e.setAttribute(\"frameborder\",\"0\"),e.setAttribute(\"allowfullscreen\",\"1\"),e.setAttribute(\"allow\", \"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\"),this.parentNode.replaceChild(e,this)}document.addEventListener(\"DOMContentLoaded\",function(){var e,t,a=document.getElementsByClassName(\"rll-youtube-player\");for(t=0;t<a.length;t++)e=document.createElement(\"div\"),e.setAttribute(\"data-id\",a[t].dataset.id),e.setAttribute(\"data-query\", a[t].dataset.query),e.innerHTML=lazyLoadThumb(a[t].dataset.id),e.onclick=lazyLoadYoutubeIframe,a[t].appendChild(e)});</script>";
243
+ }
244
+
245
+ /**
246
+ * Inserts the CSS to style the Youtube thumbnail container
247
+ *
248
+ * @param array $args Array of arguments to populate the CSS.
249
+ * @return void
250
+ */
251
+ public function insertYoutubeThumbnailCSS($args = [])
252
+ {
253
+ wp_register_style('rocket-lazyload', false);
254
+ wp_enqueue_style('rocket-lazyload');
255
+ wp_add_inline_style('rocket-lazyload', $this->getYoutubeThumbnailCSS($args));
256
+ }
257
+
258
+ /**
259
+ * Returns the CSS for the Youtube Thumbnail
260
+ *
261
+ * @param array $args Array of arguments to populate the CSS.
262
+ * @return string
263
+ */
264
+ public function getYoutubeThumbnailCSS($args = [])
265
+ {
266
+ $defaults = [
267
+ 'base_url' => '',
268
+ 'responsive_embeds' => true,
269
+ ];
270
+
271
+ $args = wp_parse_args($args, $defaults);
272
+
273
+ $css = '.rll-youtube-player{position:relative;padding-bottom:56.23%;height:0;overflow:hidden;max-width:100%;}.rll-youtube-player iframe{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;background:0 0}.rll-youtube-player img{bottom:0;display:block;left:0;margin:auto;max-width:100%;width:100%;position:absolute;right:0;top:0;border:none;height:auto;cursor:pointer;-webkit-transition:.4s all;-moz-transition:.4s all;transition:.4s all}.rll-youtube-player img:hover{-webkit-filter:brightness(75%)}.rll-youtube-player .play{height:72px;width:72px;left:50%;top:50%;margin-left:-36px;margin-top:-36px;position:absolute;background:url(' . $args['base_url'] . 'img/youtube.png) no-repeat;cursor:pointer}';
274
+
275
+ if ($args['responsive_embeds']) {
276
+ $css .= '.wp-has-aspect-ratio .rll-youtube-player{position:absolute;padding-bottom:0;width:100%;height:100%;top:0;bottom:0;left:0;right:0}';
277
+ }
278
+
279
+ return $css;
280
+ }
281
+
282
+ /**
283
+ * Inserts the CSS needed when Javascript is not enabled to keep the display correct
284
+ */
285
+ public function insertNoJSCSS()
286
+ {
287
+ echo $this->getNoJSCSS();
288
+ }
289
+
290
+ /**
291
+ * Returns the CSS to correctly display images when JavaScript is disabled
292
+ *
293
+ * @return string
294
+ */
295
+ public function getNoJSCSS()
296
+ {
297
+ return '<noscript><style id="rocket-lazyload-nojs-css">.rll-youtube-player, [data-lazy-src]{display:none !important;}</style></noscript>';
298
+ }
299
+ }
src/Dependencies/RocketLazyload/Iframe.php CHANGED
@@ -1,202 +1,202 @@
1
- <?php
2
- /**
3
- * Handles lazyloading of iframes
4
- *
5
- * @package RocketLazyload
6
- */
7
-
8
- namespace RocketLazyLoadPlugin\Dependencies\RocketLazyload;
9
-
10
- /**
11
- * A class to provide the methods needed to lazyload iframes in WP Rocket and Lazyload by WP Rocket
12
- */
13
- class Iframe
14
- {
15
- /**
16
- * Finds iframes in the HTML provided and call the methods to lazyload them
17
- *
18
- * @param string $html Original HTML.
19
- * @param string $buffer Content to parse.
20
- * @param array $args Array of arguments to use.
21
- * @return string
22
- */
23
- public function lazyloadIframes($html, $buffer, $args = [])
24
- {
25
- $defaults = [
26
- 'youtube' => false,
27
- ];
28
-
29
- $args = wp_parse_args($args, $defaults);
30
-
31
- if (! preg_match_all('@<iframe(?<atts>\s.+)>.*</iframe>@iUs', $buffer, $iframes, PREG_SET_ORDER) ) {
32
- return $html;
33
- }
34
-
35
- $iframes = array_unique($iframes, SORT_REGULAR);
36
-
37
- foreach ($iframes as $iframe) {
38
- if ($this->isIframeExcluded($iframe)) {
39
- continue;
40
- }
41
-
42
- // Given the previous regex pattern, $iframe['atts'] starts with a whitespace character.
43
- if (! preg_match('@\ssrc\s*=\s*(\'|")(?<src>.*)\1@iUs', $iframe['atts'], $atts)) {
44
- continue;
45
- }
46
-
47
- $iframe['src'] = trim($atts['src']);
48
-
49
- if ('' === $iframe['src']) {
50
- continue;
51
- }
52
-
53
- if ($args['youtube']) {
54
- $iframe_lazyload = $this->replaceYoutubeThumbnail($iframe);
55
- }
56
-
57
- if (empty($iframe_lazyload)) {
58
- $iframe_lazyload = $this->replaceIframe($iframe);
59
- }
60
-
61
- $html = str_replace($iframe[0], $iframe_lazyload, $html);
62
-
63
- unset($iframe_lazyload);
64
- }
65
-
66
- return $html;
67
- }
68
-
69
- /**
70
- * Checks if the provided iframe is excluded from lazyload
71
- *
72
- * @param array $iframe Array of matched patterns.
73
- * @return boolean
74
- */
75
- public function isIframeExcluded($iframe)
76
- {
77
-
78
- foreach ($this->getExcludedPatterns() as $excluded_pattern) {
79
- if (strpos($iframe[0], $excluded_pattern) !== false) {
80
- return true;
81
- }
82
- }
83
-
84
- return false;
85
- }
86
-
87
- /**
88
- * Gets patterns excluded from lazyload for iframes
89
- *
90
- * @since 2.1.1
91
- *
92
- * @return array
93
- */
94
- private function getExcludedPatterns()
95
- {
96
- /**
97
- * Filters the patterns excluded from lazyload for iframes
98
- *
99
- * @since 2.1.1
100
- *
101
- * @param array $excluded_patterns Array of excluded patterns.
102
- */
103
- return apply_filters(
104
- 'rocket_lazyload_iframe_excluded_patterns',
105
- [
106
- 'gform_ajax_frame',
107
- 'data-no-lazy=',
108
- 'recaptcha/api/fallback',
109
- 'loading="eager"',
110
- ]
111
- );
112
- }
113
-
114
- /**
115
- * Applies lazyload on the iframe provided
116
- *
117
- * @param array $iframe Array of matched elements.
118
- * @return string
119
- */
120
- private function replaceIframe($iframe)
121
- {
122
- /**
123
- * Filter the LazyLoad placeholder on src attribute
124
- *
125
- * @since 1.0
126
- *
127
- * @param string $placeholder placeholder that will be printed.
128
- */
129
- $placeholder = apply_filters('rocket_lazyload_placeholder', 'about:blank');
130
-
131
- $placeholder_atts = str_replace($iframe['src'], $placeholder, $iframe['atts']);
132
- $iframe_lazyload = str_replace($iframe['atts'], $placeholder_atts . ' data-rocket-lazyload="fitvidscompatible" data-lazy-src="' . esc_url($iframe['src']) . '"', $iframe[0]);
133
-
134
- if (! preg_match('@\sloading\s*=\s*(\'|")(?:lazy|auto)\1@i', $iframe_lazyload)) {
135
- $iframe_lazyload = str_replace('<iframe', '<iframe loading="lazy"', $iframe_lazyload);
136
- }
137
-
138
- /**
139
- * Filter the LazyLoad HTML output on iframes
140
- *
141
- * @since 1.0
142
- *
143
- * @param array $html Output that will be printed.
144
- */
145
- $iframe_lazyload = apply_filters('rocket_lazyload_iframe_html', $iframe_lazyload);
146
- $iframe_lazyload .= '<noscript>' . $iframe[0] . '</noscript>';
147
-
148
- return $iframe_lazyload;
149
- }
150
-
151
- /**
152
- * Replaces the iframe provided by the Youtube thumbnail
153
- *
154
- * @param array $iframe Array of matched elements.
155
- * @return bool|string
156
- */
157
- private function replaceYoutubeThumbnail($iframe)
158
- {
159
- $youtube_id = $this->getYoutubeIDFromURL($iframe['src']);
160
-
161
- if (! $youtube_id) {
162
- return false;
163
- }
164
-
165
- $query = wp_parse_url(htmlspecialchars_decode($iframe['src']), PHP_URL_QUERY);
166
-
167
- /**
168
- * Filter the LazyLoad HTML output on Youtube iframes
169
- *
170
- * @since 2.11
171
- *
172
- * @param array $html Output that will be printed.
173
- */
174
- $youtube_lazyload = apply_filters('rocket_lazyload_youtube_html', '<div class="rll-youtube-player" data-id="' . esc_attr($youtube_id) . '" data-query="' . esc_attr($query) . '"></div>');
175
- $youtube_lazyload .= '<noscript>' . $iframe[0] . '</noscript>';
176
-
177
- return $youtube_lazyload;
178
- }
179
-
180
- /**
181
- * Gets the Youtube ID from the URL provided
182
- *
183
- * @param string $url URL to search.
184
- * @return bool|string
185
- */
186
- public function getYoutubeIDFromURL($url)
187
- {
188
- $pattern = '#^(?:https?:)?(?://)?(?:www\.)?(?:youtu\.be|youtube\.com|youtube-nocookie\.com)/(?:embed/|v/|watch/?\?v=)?([\w-]{11})#iU';
189
- $result = preg_match($pattern, $url, $matches);
190
-
191
- if (! $result) {
192
- return false;
193
- }
194
-
195
- // exclude playlist.
196
- if ('videoseries' === $matches[1]) {
197
- return false;
198
- }
199
-
200
- return $matches[1];
201
- }
202
- }
1
+ <?php
2
+ /**
3
+ * Handles lazyloading of iframes
4
+ *
5
+ * @package RocketLazyload
6
+ */
7
+
8
+ namespace RocketLazyLoadPlugin\Dependencies\RocketLazyload;
9
+
10
+ /**
11
+ * A class to provide the methods needed to lazyload iframes in WP Rocket and Lazyload by WP Rocket
12
+ */
13
+ class Iframe
14
+ {
15
+ /**
16
+ * Finds iframes in the HTML provided and call the methods to lazyload them
17
+ *
18
+ * @param string $html Original HTML.
19
+ * @param string $buffer Content to parse.
20
+ * @param array $args Array of arguments to use.
21
+ * @return string
22
+ */
23
+ public function lazyloadIframes($html, $buffer, $args = [])
24
+ {
25
+ $defaults = [
26
+ 'youtube' => false,
27
+ ];
28
+
29
+ $args = wp_parse_args($args, $defaults);
30
+
31
+ if (! preg_match_all('@<iframe(?<atts>\s.+)>.*</iframe>@iUs', $buffer, $iframes, PREG_SET_ORDER) ) {
32
+ return $html;
33
+ }
34
+
35
+ $iframes = array_unique($iframes, SORT_REGULAR);
36
+
37
+ foreach ($iframes as $iframe) {
38
+ if ($this->isIframeExcluded($iframe)) {
39
+ continue;
40
+ }
41
+
42
+ // Given the previous regex pattern, $iframe['atts'] starts with a whitespace character.
43
+ if (! preg_match('@\ssrc\s*=\s*(\'|")(?<src>.*)\1@iUs', $iframe['atts'], $atts)) {
44
+ continue;
45
+ }
46
+
47
+ $iframe['src'] = trim($atts['src']);
48
+
49
+ if ('' === $iframe['src']) {
50
+ continue;
51
+ }
52
+
53
+ if ($args['youtube']) {
54
+ $iframe_lazyload = $this->replaceYoutubeThumbnail($iframe);
55
+ }
56
+
57
+ if (empty($iframe_lazyload)) {
58
+ $iframe_lazyload = $this->replaceIframe($iframe);
59
+ }
60
+
61
+ $html = str_replace($iframe[0], $iframe_lazyload, $html);
62
+
63
+ unset($iframe_lazyload);
64
+ }
65
+
66
+ return $html;
67
+ }
68
+
69
+ /**
70
+ * Checks if the provided iframe is excluded from lazyload
71
+ *
72
+ * @param array $iframe Array of matched patterns.
73
+ * @return boolean
74
+ */
75
+ public function isIframeExcluded($iframe)
76
+ {
77
+
78
+ foreach ($this->getExcludedPatterns() as $excluded_pattern) {
79
+ if (strpos($iframe[0], $excluded_pattern) !== false) {
80
+ return true;
81
+ }
82
+ }
83
+
84
+ return false;
85
+ }
86
+
87
+ /**
88
+ * Gets patterns excluded from lazyload for iframes
89
+ *
90
+ * @since 2.1.1
91
+ *
92
+ * @return array
93
+ */
94
+ private function getExcludedPatterns()
95
+ {
96
+ /**
97
+ * Filters the patterns excluded from lazyload for iframes
98
+ *
99
+ * @since 2.1.1
100
+ *
101
+ * @param array $excluded_patterns Array of excluded patterns.
102
+ */
103
+ return apply_filters(
104
+ 'rocket_lazyload_iframe_excluded_patterns',
105
+ [
106
+ 'gform_ajax_frame',
107
+ 'data-no-lazy=',
108
+ 'recaptcha/api/fallback',
109
+ 'loading="eager"',
110
+ ]
111
+ );
112
+ }
113
+
114
+ /**
115
+ * Applies lazyload on the iframe provided
116
+ *
117
+ * @param array $iframe Array of matched elements.
118
+ * @return string
119
+ */
120
+ private function replaceIframe($iframe)
121
+ {
122
+ /**
123
+ * Filter the LazyLoad placeholder on src attribute
124
+ *
125
+ * @since 1.0
126
+ *
127
+ * @param string $placeholder placeholder that will be printed.
128
+ */
129
+ $placeholder = apply_filters('rocket_lazyload_placeholder', 'about:blank');
130
+
131
+ $placeholder_atts = str_replace($iframe['src'], $placeholder, $iframe['atts']);
132
+ $iframe_lazyload = str_replace($iframe['atts'], $placeholder_atts . ' data-rocket-lazyload="fitvidscompatible" data-lazy-src="' . esc_url($iframe['src']) . '"', $iframe[0]);
133
+
134
+ if (! preg_match('@\sloading\s*=\s*(\'|")(?:lazy|auto)\1@i', $iframe_lazyload)) {
135
+ $iframe_lazyload = str_replace('<iframe', '<iframe loading="lazy"', $iframe_lazyload);
136
+ }
137
+
138
+ /**
139
+ * Filter the LazyLoad HTML output on iframes
140
+ *
141
+ * @since 1.0
142
+ *
143
+ * @param array $html Output that will be printed.
144
+ */
145
+ $iframe_lazyload = apply_filters('rocket_lazyload_iframe_html', $iframe_lazyload);
146
+ $iframe_lazyload .= '<noscript>' . $iframe[0] . '</noscript>';
147
+
148
+ return $iframe_lazyload;
149
+ }
150
+
151
+ /**
152
+ * Replaces the iframe provided by the Youtube thumbnail
153
+ *
154
+ * @param array $iframe Array of matched elements.
155
+ * @return bool|string
156
+ */
157
+ private function replaceYoutubeThumbnail($iframe)
158
+ {
159
+ $youtube_id = $this->getYoutubeIDFromURL($iframe['src']);
160
+
161
+ if (! $youtube_id) {
162
+ return false;
163
+ }
164
+
165
+ $query = wp_parse_url(htmlspecialchars_decode($iframe['src']), PHP_URL_QUERY);
166
+
167
+ /**
168
+ * Filter the LazyLoad HTML output on Youtube iframes
169
+ *
170
+ * @since 2.11
171
+ *
172
+ * @param array $html Output that will be printed.
173
+ */
174
+ $youtube_lazyload = apply_filters('rocket_lazyload_youtube_html', '<div class="rll-youtube-player" data-id="' . esc_attr($youtube_id) . '" data-query="' . esc_attr($query) . '"></div>');
175
+ $youtube_lazyload .= '<noscript>' . $iframe[0] . '</noscript>';
176
+
177
+ return $youtube_lazyload;
178
+ }
179
+
180
+ /**
181
+ * Gets the Youtube ID from the URL provided
182
+ *
183
+ * @param string $url URL to search.
184
+ * @return bool|string
185
+ */
186
+ public function getYoutubeIDFromURL($url)
187
+ {
188
+ $pattern = '#^(?:https?:)?(?://)?(?:www\.)?(?:youtu\.be|youtube\.com|youtube-nocookie\.com)/(?:embed/|v/|watch/?\?v=)?([\w-]{11})#iU';
189
+ $result = preg_match($pattern, $url, $matches);
190
+
191
+ if (! $result) {
192
+ return false;
193
+ }
194
+
195
+ // exclude playlist.
196
+ if ('videoseries' === $matches[1]) {
197
+ return false;
198
+ }
199
+
200
+ return $matches[1];
201
+ }
202
+ }
src/Dependencies/RocketLazyload/Image.php CHANGED
@@ -1,474 +1,474 @@
1
- <?php
2
- /**
3
- * Handles lazyloading of images
4
- *
5
- * @package RocketLazyload
6
- */
7
-
8
- namespace RocketLazyLoadPlugin\Dependencies\RocketLazyload;
9
-
10
- /**
11
- * A class to provide the methods needed to lazyload images in WP Rocket and Lazyload by WP Rocket
12
- */
13
- class Image
14
- {
15
- /**
16
- * Finds the images to be lazyloaded and call the callback method to replace them.
17
- *
18
- * @param string $html Original HTML.
19
- * @param string $buffer Content to parse.
20
- * @return string
21
- */
22
- public function lazyloadImages($html, $buffer)
23
- {
24
- if (! preg_match_all('#<img(?<atts>\s.+)\s?/?>#iUs', $buffer, $images, PREG_SET_ORDER)) {
25
- return $html;
26
- }
27
-
28
- $images = array_unique($images, SORT_REGULAR);
29
-
30
- foreach ($images as $image) {
31
- $image = $this->canLazyload($image);
32
-
33
- if (! $image) {
34
- continue;
35
- }
36
-
37
- $image_lazyload = $this->replaceImage($image);
38
- $image_lazyload .= $this->noscript($image[0]);
39
- $html = str_replace($image[0], $image_lazyload, $html);
40
-
41
- unset($image_lazyload);
42
- }
43
-
44
- return $html;
45
- }
46
-
47
- /**
48
- * Applies lazyload on background images defined in style attributes
49
- *
50
- * @param string $html Original HTML.
51
- * @param string $buffer Content to parse.
52
- * @return string
53
- */
54
- public function lazyloadBackgroundImages($html, $buffer)
55
- {
56
- if (! preg_match_all('#<(?<tag>div|section|span|li)\s+(?<before>[^>]+[\'"\s])?style\s*=\s*([\'"])(?<styles>.*?)\3(?<after>[^>]*)>#is', $buffer, $elements, PREG_SET_ORDER)) {
57
- return $html;
58
- }
59
-
60
- foreach ($elements as $element) {
61
- if ($this->isExcluded($element['before'] . $element['after'], $this->getExcludedAttributes())) {
62
- continue;
63
- }
64
-
65
- if (! preg_match('#background-image\s*:\s*(?<attr>\s*url\s*\((?<url>[^)]+)\))\s*;?#is', $element['styles'], $url)) {
66
- continue;
67
- }
68
-
69
- $url['url'] = trim($url['url'], '\'" ');
70
-
71
- if ($this->isExcluded($url['url'], $this->getExcludedSrc())) {
72
- continue;
73
- }
74
-
75
- $lazy_bg = $this->addLazyCLass($element[0]);
76
- $lazy_bg = str_replace($url[0], '', $lazy_bg);
77
- $lazy_bg = str_replace('<' . $element['tag'], '<' . $element['tag'] . ' data-bg="url(' . esc_attr($url['url']) . ')"', $lazy_bg);
78
-
79
- $html = str_replace($element[0], $lazy_bg, $html);
80
- unset($lazy_bg);
81
- }
82
-
83
- return $html;
84
- }
85
-
86
- /**
87
- * Add the identifier class to the element
88
- *
89
- * @param string $element Element to add the class to.
90
- * @return string
91
- */
92
- private function addLazyClass($element)
93
- {
94
- if (preg_match('#class=["\']?(?<classes>[^"\'>]*)["\']?#is', $element, $class)) {
95
- $classes = str_replace($class['classes'], $class['classes'] . ' rocket-lazyload', $class[0]);
96
- $element = str_replace($class[0], $classes, $element);
97
-
98
- return $element;
99
- }
100
-
101
- return preg_replace('#<(img|div|section|li|span)([^>]*)>#is', '<\1 class="rocket-lazyload"\2>', $element);
102
- }
103
-
104
- /**
105
- * Applies lazyload on picture elements found in the HTML.
106
- *
107
- * @param string $html Original HTML.
108
- * @param string $buffer Content to parse.
109
- * @return string
110
- */
111
- public function lazyloadPictures($html, $buffer)
112
- {
113
- if (! preg_match_all('#<picture(?:.*)?>(?<sources>.*)</picture>#iUs', $buffer, $pictures, PREG_SET_ORDER)) {
114
- return $html;
115
- }
116
-
117
- $pictures = array_unique($pictures, SORT_REGULAR);
118
- $excluded = array_merge($this->getExcludedAttributes(), $this->getExcludedSrc());
119
-
120
- foreach ($pictures as $picture) {
121
- if ($this->isExcluded($picture[0], $excluded)) {
122
- continue;
123
- }
124
-
125
- if (preg_match_all('#<source(?<atts>\s.+)>#iUs', $picture['sources'], $sources, PREG_SET_ORDER)) {
126
- $sources = array_unique($sources, SORT_REGULAR);
127
-
128
- $lazy_sources = 0;
129
-
130
- foreach ($sources as $source) {
131
- $lazyload_srcset = preg_replace('/([\s"\'])srcset/i', '\1data-lazy-srcset', $source[0]);
132
- $html = str_replace($source[0], $lazyload_srcset, $html);
133
-
134
- unset($lazyload_srcset);
135
- $lazy_sources++;
136
- }
137
- }
138
-
139
- if (0 === $lazy_sources) {
140
- continue;
141
- }
142
-
143
- if (! preg_match('#<img(?<atts>\s.+)\s?/?>#iUs', $picture[0], $img)) {
144
- continue;
145
- }
146
-
147
- $img = $this->canLazyload($img);
148
-
149
- if (! $img) {
150
- continue;
151
- }
152
-
153
- $img_lazy = $this->replaceImage($img);
154
- $html = str_replace($img[0], $img_lazy, $html);
155
-
156
- unset($img_lazy);
157
- }
158
-
159
- return $html;
160
- }
161
-
162
- /**
163
- * Checks if the image can be lazyloaded
164
- *
165
- * @param Array $image Array of image data coming from Regex.
166
- * @return bool|Array
167
- */
168
- private function canLazyload($image)
169
- {
170
- if ($this->isExcluded($image['atts'], $this->getExcludedAttributes())) {
171
- return false;
172
- }
173
-
174
- // Given the previous regex pattern, $image['atts'] starts with a whitespace character.
175
- if (! preg_match('@\ssrc\s*=\s*(\'|")(?<src>.*)\1@iUs', $image['atts'], $atts)) {
176
- return false;
177
- }
178
-
179
- $image['src'] = trim($atts['src']);
180
-
181
- if ('' === $image['src']) {
182
- return false;
183
- }
184
-
185
- if ($this->isExcluded($image['src'], $this->getExcludedSrc())) {
186
- return false;
187
- }
188
-
189
- // Don't apply LazyLoad on images from WP Retina x2.
190
- if (function_exists('wr2x_picture_rewrite')) {
191
- if (wr2x_get_retina(trailingslashit(ABSPATH) . wr2x_get_pathinfo_from_image_src(trim($image['src'], '"')))) {
192
- return false;
193
- }
194
- }
195
-
196
- return $image;
197
- }
198
-
199
- /**
200
- * Checks if the provided string matches with the provided excluded patterns
201
- *
202
- * @param string $string String to check.
203
- * @param array $excluded_values Patterns to match against.
204
- * @return boolean
205
- */
206
- public function isExcluded($string, $excluded_values)
207
- {
208
- if (! is_array($excluded_values)) {
209
- (array) $excluded_values;
210
- }
211
-
212
- if (empty($excluded_values)) {
213
- return false;
214
- }
215
-
216
- foreach ($excluded_values as $excluded_value) {
217
- if (strpos($string, $excluded_value) !== false) {
218
- return true;
219
- }
220
- }
221
-
222
- return false;
223
- }
224
-
225
- /**
226
- * Returns the list of excluded attributes
227
- *
228
- * @return array
229
- */
230
- public function getExcludedAttributes()
231
- {
232
- /**
233
- * Filters the attributes used to prevent lazylad from being applied
234
- *
235
- * @since 1.0
236
- * @author Remy Perona
237
- *
238
- * @param array $excluded_attributes An array of excluded attributes.
239
- */
240
- return apply_filters(
241
- 'rocket_lazyload_excluded_attributes',
242
- [
243
- 'data-src=',
244
- 'data-no-lazy=',
245
- 'data-lazy-original=',
246
- 'data-lazy-src=',
247
- 'data-lazysrc=',
248
- 'data-lazyload=',
249
- 'data-bgposition=',
250
- 'data-envira-src=',
251
- 'fullurl=',
252
- 'lazy-slider-img=',
253
- 'data-srcset=',
254
- 'class="ls-l',
255
- 'class="ls-bg',
256
- 'soliloquy-image',
257
- 'loading="eager"',
258
- 'swatch-img',
259
- 'data-height-percentage',
260
- 'data-large_image',
261
- 'avia-bg-style-fixed',
262
- ]
263
- );
264
- }
265
-
266
- /**
267
- * Returns the list of excluded src
268
- *
269
- * @return array
270
- */
271
- public function getExcludedSrc()
272
- {
273
- /**
274
- * Filters the src used to prevent lazylad from being applied
275
- *
276
- * @since 1.0
277
- * @author Remy Perona
278
- *
279
- * @param array $excluded_src An array of excluded src.
280
- */
281
- return apply_filters(
282
- 'rocket_lazyload_excluded_src',
283
- [
284
- '/wpcf7_captcha/',
285
- 'timthumb.php?src',
286
- 'woocommerce/assets/images/placeholder.png',
287
- ]
288
- );
289
- }
290
-
291
- /**
292
- * Replaces the original image by the lazyload one
293
- *
294
- * @param array $image Array of matches elements.
295
- * @return string
296
- */
297
- private function replaceImage($image)
298
- {
299
- $width = 0;
300
- $height = 0;
301
-
302
- if (preg_match('@[\s"\']width\s*=\s*(\'|")(?<width>.*)\1@iUs', $image['atts'], $atts)) {
303
- $width = absint($atts['width']);
304
- }
305
-
306
- if (preg_match('@[\s"\']height\s*=\s*(\'|")(?<height>.*)\1@iUs', $image['atts'], $atts)) {
307
- $height = absint($atts['height']);
308
- }
309
-
310
- $placeholder_atts = preg_replace('@\ssrc\s*=\s*(\'|")(?<src>.*)\1@iUs', ' src="' . $this->getPlaceholder($width, $height) . '"', $image['atts']);
311
-
312
- $image_lazyload = str_replace($image['atts'], $placeholder_atts . ' data-lazy-src="' . $image['src'] . '"', $image[0]);
313
-
314
- if (! preg_match('@\sloading\s*=\s*(\'|")(?:lazy|auto)\1@i', $image_lazyload)) {
315
- $image_lazyload = str_replace('<img', '<img loading="lazy"', $image_lazyload);
316
- }
317
-
318
- /**
319
- * Filter the LazyLoad HTML output
320
- *
321
- * @since 1.0
322
- *
323
- * @param string $html Output that will be printed
324
- */
325
- $image_lazyload = apply_filters('rocket_lazyload_html', $image_lazyload);
326
-
327
- return $image_lazyload;
328
- }
329
-
330
- /**
331
- * Returns the HTML tag wrapped inside noscript tags
332
- *
333
- * @param string $element Element to wrap.
334
- * @return string
335
- */
336
- private function noscript($element)
337
- {
338
- return '<noscript>' . $element . '</noscript>';
339
- }
340
-
341
- /**
342
- * Applies lazyload on srcset and sizes attributes
343
- *
344
- * @param string $html HTML image tag.
345
- * @return string
346
- */
347
- public function lazyloadResponsiveAttributes($html)
348
- {
349
- $html = preg_replace('/[\s|"|\'](srcset)\s*=\s*("|\')([^"|\']+)\2/i', ' data-lazy-$1=$2$3$2', $html);
350
- $html = preg_replace('/[\s|"|\'](sizes)\s*=\s*("|\')([^"|\']+)\2/i', ' data-lazy-$1=$2$3$2', $html);
351
-
352
- return $html;
353
- }
354
-
355
- /**
356
- * Finds patterns matching smiley and call the callback method to replace them with the image
357
- *
358
- * @param string $text Content to search in.
359
- * @return string
360
- */
361
- public function convertSmilies($text)
362
- {
363
- global $wp_smiliessearch;
364
-
365
- if (! get_option('use_smilies') || empty($wp_smiliessearch)) {
366
- return $text;
367
- }
368
-
369
- $output = '';
370
- // HTML loop taken from texturize function, could possible be consolidated.
371
- $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between.
372
- $stop = count($textarr);// loop stuff.
373
-
374
- // Ignore proessing of specific tags.
375
- $tags_to_ignore = 'code|pre|style|script|textarea';
376
- $ignore_block_element = '';
377
-
378
- for ($i = 0; $i < $stop; $i++) {
379
- $content = $textarr[ $i ];
380
-
381
- // If we're in an ignore block, wait until we find its closing tag.
382
- if ('' === $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
383
- $ignore_block_element = $matches[1];
384
- }
385
-
386
- // If it's not a tag and not in ignore block.
387
- if ('' === $ignore_block_element && strlen($content) > 0 && '<' !== $content[0]) {
388
- $content = preg_replace_callback($wp_smiliessearch, [$this, 'translateSmiley'], $content);
389
- }
390
-
391
- // did we exit ignore block.
392
- if ('' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content) {
393
- $ignore_block_element = '';
394
- }
395
-
396
- $output .= $content;
397
- }
398
-
399
- return $output;
400
- }
401
-
402
- /**
403
- * Replace matches by smiley image, lazyloaded
404
- *
405
- * @param array $matches Array of matches.
406
- * @return string
407
- */
408
- private function translateSmiley($matches)
409
- {
410
- global $wpsmiliestrans;
411
-
412
- if (count($matches) === 0) {
413
- return '';
414
- }
415
-
416
- $smiley = trim(reset($matches));
417
- $img = $wpsmiliestrans[ $smiley ];
418
-
419
- $matches = [];
420
- $ext = preg_match('/\.([^.]+)$/', $img, $matches) ? strtolower($matches[1]) : false;
421
- $image_exts = ['jpg', 'jpeg', 'jpe', 'gif', 'png'];
422
-
423
- // Don't convert smilies that aren't images - they're probably emoji.
424
- if (! in_array($ext, $image_exts, true)) {
425
- return $img;
426
- }
427
-
428
- /**
429
- * Filter the Smiley image URL before it's used in the image element.
430
- *
431
- * @since 2.9.0
432
- *
433
- * @param string $smiley_url URL for the smiley image.
434
- * @param string $img Filename for the smiley image.
435
- * @param string $site_url Site URL, as returned by site_url().
436
- */
437
- $src_url = apply_filters('smilies_src', includes_url("images/smilies/$img"), $img, site_url());
438
-
439
- // Don't LazyLoad if process is stopped for these reasons.
440
- if (is_feed() || is_preview()) {
441
- return sprintf(' <img src="%s" alt="%s" class="wp-smiley" /> ', esc_url($src_url), esc_attr($smiley));
442
- }
443
-
444
- return sprintf(' <img src="%s" data-lazy-src="%s" alt="%s" class="wp-smiley" /> ', $this->getPlaceholder(), esc_url($src_url), esc_attr($smiley));
445
- }
446
-
447
- /**
448
- * Returns the placeholder for the src attribute
449
- *
450
- * @since 1.2
451
- * @author Remy Perona
452
- *
453
- * @param int $width Width of the placeholder image. Default 0.
454
- * @param int $height Height of the placeholder image. Default 0.
455
- * @return string
456
- */
457
- public function getPlaceholder($width = 0, $height = 0)
458
- {
459
- $width = 0 === $width ? 0 : absint($width);
460
- $height = 0 === $height ? 0 : absint($height);
461
-
462
- $placeholder = str_replace(' ', '%20', "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 $width $height'%3E%3C/svg%3E");
463
- /**
464
- * Filter the image lazyLoad placeholder on src attribute
465
- *
466
- * @since 1.1
467
- *
468
- * @param string $placeholder Placeholder that will be printed.
469
- * @param int $width Placeholder width.
470
- * @param int $height Placeholder height.
471
- */
472
- return apply_filters('rocket_lazyload_placeholder', $placeholder, $width, $height);
473
- }
474
- }
1
+ <?php
2
+ /**
3
+ * Handles lazyloading of images
4
+ *
5
+ * @package RocketLazyload
6
+ */
7
+
8
+ namespace RocketLazyLoadPlugin\Dependencies\RocketLazyload;
9
+
10
+ /**
11
+ * A class to provide the methods needed to lazyload images in WP Rocket and Lazyload by WP Rocket
12
+ */
13
+ class Image
14
+ {
15
+ /**
16
+ * Finds the images to be lazyloaded and call the callback method to replace them.
17
+ *
18
+ * @param string $html Original HTML.
19
+ * @param string $buffer Content to parse.
20
+ * @return string
21
+ */
22
+ public function lazyloadImages($html, $buffer)
23
+ {
24
+ if (! preg_match_all('#<img(?<atts>\s.+)\s?/?>#iUs', $buffer, $images, PREG_SET_ORDER)) {
25
+ return $html;
26
+ }
27
+
28
+ $images = array_unique($images, SORT_REGULAR);
29
+
30
+ foreach ($images as $image) {
31
+ $image = $this->canLazyload($image);
32
+
33
+ if (! $image) {
34
+ continue;
35
+ }
36
+
37
+ $image_lazyload = $this->replaceImage($image);
38
+ $image_lazyload .= $this->noscript($image[0]);
39
+ $html = str_replace($image[0], $image_lazyload, $html);
40
+
41
+ unset($image_lazyload);
42
+ }
43
+
44
+ return $html;
45
+ }
46
+
47
+ /**
48
+ * Applies lazyload on background images defined in style attributes
49
+ *
50
+ * @param string $html Original HTML.
51
+ * @param string $buffer Content to parse.
52
+ * @return string
53
+ */
54
+ public function lazyloadBackgroundImages($html, $buffer)
55
+ {
56
+ if (! preg_match_all('#<(?<tag>div|section|span|li)\s+(?<before>[^>]+[\'"\s])?style\s*=\s*([\'"])(?<styles>.*?)\3(?<after>[^>]*)>#is', $buffer, $elements, PREG_SET_ORDER)) {
57
+ return $html;
58
+ }
59
+
60
+ foreach ($elements as $element) {
61
+ if ($this->isExcluded($element['before'] . $element['after'], $this->getExcludedAttributes())) {
62
+ continue;
63
+ }
64
+
65
+ if (! preg_match('#background-image\s*:\s*(?<attr>\s*url\s*\((?<url>[^)]+)\))\s*;?#is', $element['styles'], $url)) {
66
+ continue;
67
+ }
68
+
69
+ $url['url'] = trim($url['url'], '\'" ');
70
+
71
+ if ($this->isExcluded($url['url'], $this->getExcludedSrc())) {
72
+ continue;
73
+ }
74
+
75
+ $lazy_bg = $this->addLazyCLass($element[0]);
76
+ $lazy_bg = str_replace($url[0], '', $lazy_bg);
77
+ $lazy_bg = str_replace('<' . $element['tag'], '<' . $element['tag'] . ' data-bg="url(' . esc_attr($url['url']) . ')"', $lazy_bg);
78
+
79
+ $html = str_replace($element[0], $lazy_bg, $html);
80
+ unset($lazy_bg);
81
+ }
82
+
83
+ return $html;
84
+ }
85
+
86
+ /**
87
+ * Add the identifier class to the element
88
+ *
89
+ * @param string $element Element to add the class to.
90
+ * @return string
91
+ */
92
+ private function addLazyClass($element)
93
+ {
94
+ if (preg_match('#class=["\']?(?<classes>[^"\'>]*)["\']?#is', $element, $class)) {
95
+ $classes = str_replace($class['classes'], $class['classes'] . ' rocket-lazyload', $class[0]);
96
+ $element = str_replace($class[0], $classes, $element);
97
+
98
+ return $element;
99
+ }
100
+
101
+ return preg_replace('#<(img|div|section|li|span)([^>]*)>#is', '<\1 class="rocket-lazyload"\2>', $element);
102
+ }
103
+
104
+ /**
105
+ * Applies lazyload on picture elements found in the HTML.
106
+ *
107
+ * @param string $html Original HTML.
108
+ * @param string $buffer Content to parse.
109
+ * @return string
110
+ */
111
+ public function lazyloadPictures($html, $buffer)
112
+ {
113
+ if (! preg_match_all('#<picture(?:.*)?>(?<sources>.*)</picture>#iUs', $buffer, $pictures, PREG_SET_ORDER)) {
114
+ return $html;
115
+ }
116
+
117
+ $pictures = array_unique($pictures, SORT_REGULAR);
118
+ $excluded = array_merge($this->getExcludedAttributes(), $this->getExcludedSrc());
119
+
120
+ foreach ($pictures as $picture) {
121
+ if ($this->isExcluded($picture[0], $excluded)) {
122
+ continue;
123
+ }
124
+
125
+ if (preg_match_all('#<source(?<atts>\s.+)>#iUs', $picture['sources'], $sources, PREG_SET_ORDER)) {
126
+ $sources = array_unique($sources, SORT_REGULAR);
127
+
128
+ $lazy_sources = 0;
129
+
130
+ foreach ($sources as $source) {
131
+ $lazyload_srcset = preg_replace('/([\s"\'])srcset/i', '\1data-lazy-srcset', $source[0]);
132
+ $html = str_replace($source[0], $lazyload_srcset, $html);
133
+
134
+ unset($lazyload_srcset);
135
+ $lazy_sources++;
136
+ }
137
+ }
138
+
139
+ if (0 === $lazy_sources) {
140
+ continue;
141
+ }
142
+
143
+ if (! preg_match('#<img(?<atts>\s.+)\s?/?>#iUs', $picture[0], $img)) {
144
+ continue;
145
+ }
146
+
147
+ $img = $this->canLazyload($img);
148
+
149
+ if (! $img) {
150
+ continue;
151
+ }
152
+
153
+ $img_lazy = $this->replaceImage($img);
154
+ $html = str_replace($img[0], $img_lazy, $html);
155
+
156
+ unset($img_lazy);
157
+ }
158
+
159
+ return $html;
160
+ }
161
+
162
+ /**
163
+ * Checks if the image can be lazyloaded
164
+ *
165
+ * @param Array $image Array of image data coming from Regex.
166
+ * @return bool|Array
167
+ */
168
+ private function canLazyload($image)
169
+ {
170
+ if ($this->isExcluded($image['atts'], $this->getExcludedAttributes())) {
171
+ return false;
172
+ }
173
+
174
+ // Given the previous regex pattern, $image['atts'] starts with a whitespace character.
175
+ if (! preg_match('@\ssrc\s*=\s*(\'|")(?<src>.*)\1@iUs', $image['atts'], $atts)) {
176
+ return false;
177
+ }
178
+
179
+ $image['src'] = trim($atts['src']);
180
+
181
+ if ('' === $image['src']) {
182
+ return false;
183
+ }
184
+
185
+ if ($this->isExcluded($image['src'], $this->getExcludedSrc())) {
186
+ return false;
187
+ }
188
+
189
+ // Don't apply LazyLoad on images from WP Retina x2.
190
+ if (function_exists('wr2x_picture_rewrite')) {
191
+ if (wr2x_get_retina(trailingslashit(ABSPATH) . wr2x_get_pathinfo_from_image_src(trim($image['src'], '"')))) {
192
+ return false;
193
+ }
194
+ }
195
+
196
+ return $image;
197
+ }
198
+
199
+ /**
200
+ * Checks if the provided string matches with the provided excluded patterns
201
+ *
202
+ * @param string $string String to check.
203
+ * @param array $excluded_values Patterns to match against.
204
+ * @return boolean
205
+ */
206
+ public function isExcluded($string, $excluded_values)
207
+ {
208
+ if (! is_array($excluded_values)) {
209
+ (array) $excluded_values;
210
+ }
211
+
212
+ if (empty($excluded_values)) {
213
+ return false;
214
+ }
215
+
216
+ foreach ($excluded_values as $excluded_value) {
217
+ if (strpos($string, $excluded_value) !== false) {
218
+ return true;
219
+ }
220
+ }
221
+
222
+ return false;
223
+ }
224
+
225
+ /**
226
+ * Returns the list of excluded attributes
227
+ *
228
+ * @return array
229
+ */
230
+ public function getExcludedAttributes()
231
+ {
232
+ /**
233
+ * Filters the attributes used to prevent lazylad from being applied
234
+ *
235
+ * @since 1.0
236
+ * @author Remy Perona
237
+ *
238
+ * @param array $excluded_attributes An array of excluded attributes.
239
+ */
240
+ return apply_filters(
241
+ 'rocket_lazyload_excluded_attributes',
242
+ [
243
+ 'data-src=',
244
+ 'data-no-lazy=',
245
+ 'data-lazy-original=',
246
+ 'data-lazy-src=',
247
+ 'data-lazysrc=',
248
+ 'data-lazyload=',
249
+ 'data-bgposition=',
250
+ 'data-envira-src=',
251
+ 'fullurl=',
252
+ 'lazy-slider-img=',
253
+ 'data-srcset=',
254
+ 'class="ls-l',
255
+ 'class="ls-bg',
256
+ 'soliloquy-image',
257
+ 'loading="eager"',
258
+ 'swatch-img',
259
+ 'data-height-percentage',
260
+ 'data-large_image',
261
+ 'avia-bg-style-fixed',
262
+ ]
263
+ );
264
+ }
265
+
266
+ /**
267
+ * Returns the list of excluded src
268
+ *
269
+ * @return array
270
+ */
271
+ public function getExcludedSrc()
272
+ {
273
+ /**
274
+ * Filters the src used to prevent lazylad from being applied
275
+ *
276
+ * @since 1.0
277
+ * @author Remy Perona
278
+ *
279
+ * @param array $excluded_src An array of excluded src.
280
+ */
281
+ return apply_filters(
282
+ 'rocket_lazyload_excluded_src',
283
+ [
284
+ '/wpcf7_captcha/',
285
+ 'timthumb.php?src',
286
+ 'woocommerce/assets/images/placeholder.png',
287
+ ]
288
+ );
289
+ }
290
+
291
+ /**
292
+ * Replaces the original image by the lazyload one
293
+ *
294
+ * @param array $image Array of matches elements.
295
+ * @return string
296
+ */
297
+ private function replaceImage($image)
298
+ {
299
+ $width = 0;
300
+ $height = 0;
301
+
302
+ if (preg_match('@[\s"\']width\s*=\s*(\'|")(?<width>.*)\1@iUs', $image['atts'], $atts)) {
303
+ $width = absint($atts['width']);
304
+ }
305
+
306
+ if (preg_match('@[\s"\']height\s*=\s*(\'|")(?<height>.*)\1@iUs', $image['atts'], $atts)) {
307
+ $height = absint($atts['height']);
308
+ }
309
+
310
+ $placeholder_atts = preg_replace('@\ssrc\s*=\s*(\'|")(?<src>.*)\1@iUs', ' src="' . $this->getPlaceholder($width, $height) . '"', $image['atts']);
311
+
312
+ $image_lazyload = str_replace($image['atts'], $placeholder_atts . ' data-lazy-src="' . $image['src'] . '"', $image[0]);
313
+
314
+ if (! preg_match('@\sloading\s*=\s*(\'|")(?:lazy|auto)\1@i', $image_lazyload)) {
315
+ $image_lazyload = str_replace('<img', '<img loading="lazy"', $image_lazyload);
316
+ }
317
+
318
+ /**
319
+ * Filter the LazyLoad HTML output
320
+ *
321
+ * @since 1.0
322
+ *
323
+ * @param string $html Output that will be printed
324
+ */
325
+ $image_lazyload = apply_filters('rocket_lazyload_html', $image_lazyload);
326
+
327
+ return $image_lazyload;
328
+ }
329
+
330
+ /**
331
+ * Returns the HTML tag wrapped inside noscript tags
332
+ *
333
+ * @param string $element Element to wrap.
334
+ * @return string
335
+ */
336
+ private function noscript($element)
337
+ {
338
+ return '<noscript>' . $element . '</noscript>';
339
+ }
340
+
341
+ /**
342
+ * Applies lazyload on srcset and sizes attributes
343
+ *
344
+ * @param string $html HTML image tag.
345
+ * @return string
346
+ */
347
+ public function lazyloadResponsiveAttributes($html)
348
+ {
349
+ $html = preg_replace('/[\s|"|\'](srcset)\s*=\s*("|\')([^"|\']+)\2/i', ' data-lazy-$1=$2$3$2', $html);
350
+ $html = preg_replace('/[\s|"|\'](sizes)\s*=\s*("|\')([^"|\']+)\2/i', ' data-lazy-$1=$2$3$2', $html);
351
+
352
+ return $html;
353
+ }
354
+
355
+ /**
356
+ * Finds patterns matching smiley and call the callback method to replace them with the image
357
+ *
358
+ * @param string $text Content to search in.
359
+ * @return string
360
+ */
361
+ public function convertSmilies($text)
362
+ {
363
+ global $wp_smiliessearch;
364
+
365
+ if (! get_option('use_smilies') || empty($wp_smiliessearch)) {
366
+ return $text;
367
+ }
368
+
369
+ $output = '';
370
+ // HTML loop taken from texturize function, could possible be consolidated.
371
+ $textarr = preg_split('/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between.
372
+ $stop = count($textarr);// loop stuff.
373
+
374
+ // Ignore proessing of specific tags.
375
+ $tags_to_ignore = 'code|pre|style|script|textarea';
376
+ $ignore_block_element = '';
377
+
378
+ for ($i = 0; $i < $stop; $i++) {
379
+ $content = $textarr[ $i ];
380
+
381
+ // If we're in an ignore block, wait until we find its closing tag.
382
+ if ('' === $ignore_block_element && preg_match('/^<(' . $tags_to_ignore . ')>/', $content, $matches)) {
383
+ $ignore_block_element = $matches[1];
384
+ }
385
+
386
+ // If it's not a tag and not in ignore block.
387
+ if ('' === $ignore_block_element && strlen($content) > 0 && '<' !== $content[0]) {
388
+ $content = preg_replace_callback($wp_smiliessearch, [$this, 'translateSmiley'], $content);
389
+ }
390
+
391
+ // did we exit ignore block.
392
+ if ('' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content) {
393
+ $ignore_block_element = '';
394
+ }
395
+
396
+ $output .= $content;
397
+ }
398
+
399
+ return $output;
400
+ }
401
+
402
+ /**
403
+ * Replace matches by smiley image, lazyloaded
404
+ *
405
+ * @param array $matches Array of matches.
406
+ * @return string
407
+ */
408
+ private function translateSmiley($matches)
409
+ {
410
+ global $wpsmiliestrans;
411
+
412
+ if (count($matches) === 0) {
413
+ return '';
414
+ }
415
+
416
+ $smiley = trim(reset($matches));
417
+ $img = $wpsmiliestrans[ $smiley ];
418
+
419
+ $matches = [];
420
+ $ext = preg_match('/\.([^.]+)$/', $img, $matches) ? strtolower($matches[1]) : false;
421
+ $image_exts = ['jpg', 'jpeg', 'jpe', 'gif', 'png'];
422
+
423
+ // Don't convert smilies that aren't images - they're probably emoji.
424
+ if (! in_array($ext, $image_exts, true)) {
425
+ return $img;
426
+ }
427
+
428
+ /**
429
+ * Filter the Smiley image URL before it's used in the image element.
430
+ *
431
+ * @since 2.9.0
432
+ *
433
+ * @param string $smiley_url URL for the smiley image.
434
+ * @param string $img Filename for the smiley image.
435
+ * @param string $site_url Site URL, as returned by site_url().
436
+ */
437
+ $src_url = apply_filters('smilies_src', includes_url("images/smilies/$img"), $img, site_url());
438
+
439
+ // Don't LazyLoad if process is stopped for these reasons.
440
+ if (is_feed() || is_preview()) {
441
+ return sprintf(' <img src="%s" alt="%s" class="wp-smiley" /> ', esc_url($src_url), esc_attr($smiley));
442
+ }
443
+
444
+ return sprintf(' <img src="%s" data-lazy-src="%s" alt="%s" class="wp-smiley" /> ', $this->getPlaceholder(), esc_url($src_url), esc_attr($smiley));
445
+ }
446
+
447
+ /**
448
+ * Returns the placeholder for the src attribute
449
+ *
450
+ * @since 1.2
451
+ * @author Remy Perona
452
+ *
453
+ * @param int $width Width of the placeholder image. Default 0.
454
+ * @param int $height Height of the placeholder image. Default 0.
455
+ * @return string
456
+ */
457
+ public function getPlaceholder($width = 0, $height = 0)
458
+ {
459
+ $width = 0 === $width ? 0 : absint($width);
460
+ $height = 0 === $height ? 0 : absint($height);
461
+
462
+ $placeholder = str_replace(' ', '%20', "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 $width $height'%3E%3C/svg%3E");
463
+ /**
464
+ * Filter the image lazyLoad placeholder on src attribute
465
+ *
466
+ * @since 1.1
467
+ *
468
+ * @param string $placeholder Placeholder that will be printed.
469
+ * @param int $width Placeholder width.
470
+ * @param int $height Placeholder height.
471
+ */
472
+ return apply_filters('rocket_lazyload_placeholder', $placeholder, $width, $height);
473
+ }
474
+ }