You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @final since version 3.4, to be given a container instead in 4.0
25
+
* @final since version 3.4
24
26
*/
25
-
class RouterCacheWarmer implements CacheWarmerInterface
27
+
class RouterCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterface
26
28
{
27
29
protected$router;
28
30
29
31
/**
30
32
* Constructor.
31
33
*
32
-
* @param RouterInterface $router A Router instance
34
+
* @param ContainerInterface $container
33
35
*/
34
-
publicfunction__construct(RouterInterface$router)
36
+
publicfunction__construct($container)
35
37
{
36
-
$this->router = $router;
38
+
// As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected.
39
+
if ($containerinstanceof ContainerInterface) {
40
+
$this->router = $container->get('router'); // For BC, the $router property must be populated in the constructor
41
+
} elseif ($containerinstanceof RouterInterface) {
42
+
$this->router = $container;
43
+
@trigger_error(sprintf('Using a "%s" as first argument of %s is deprecated since version 3.4 and will be unsupported in version 4.0. Use a %s instead.', RouterInterface::class, __CLASS__, ContainerInterface::class), E_USER_DEPRECATED);
44
+
} else {
45
+
thrownew \InvalidArgumentException(sprintf('%s only accepts instance of Psr\Container\ContainerInterface as first argument.', __CLASS__));
0 commit comments