diff --git a/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php b/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php index 97b1ea31360ce..92a520eda3fb5 100644 --- a/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php @@ -91,7 +91,7 @@ public function getUrl($name, $parameters = array(), $schemeRelative = false) * * @return array An array with the contexts the URL is safe * - * To be made @final in 3.4, and the type-hint be changed to "\Twig\Node\Node" in 4.0. + * @final since version 3.4, type-hint to be changed to "\Twig\Node\Node" in 4.0 */ public function isUrlGenerationSafe(\Twig_Node $argsNode) { diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/RouterCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/RouterCacheWarmer.php index a650960c948e2..ffde2dcd92293 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/RouterCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/RouterCacheWarmer.php @@ -11,6 +11,8 @@ namespace Symfony\Bundle\FrameworkBundle\CacheWarmer; +use Psr\Container\ContainerInterface; +use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface; use Symfony\Component\Routing\RouterInterface; @@ -20,20 +22,28 @@ * * @author Fabien Potencier * - * @final since version 3.4, to be given a container instead in 4.0 + * @final since version 3.4 */ -class RouterCacheWarmer implements CacheWarmerInterface +class RouterCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterface { protected $router; /** * Constructor. * - * @param RouterInterface $router A Router instance + * @param ContainerInterface $container */ - public function __construct(RouterInterface $router) + public function __construct($container) { - $this->router = $router; + // As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected. + if ($container instanceof ContainerInterface) { + $this->router = $container->get('router'); // For BC, the $router property must be populated in the constructor + } elseif ($container instanceof RouterInterface) { + $this->router = $container; + @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); + } else { + throw new \InvalidArgumentException(sprintf('%s only accepts instance of Psr\Container\ContainerInterface as first argument.', __CLASS__)); + } } /** @@ -57,4 +67,14 @@ public function isOptional() { return true; } + + /** + * {@inheritdoc} + */ + public static function getSubscribedServices() + { + return array( + 'router' => RouterInterface::class, + ); + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml index 1278a0cb2208e..22bd38f8b80d6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml @@ -97,8 +97,9 @@ + - +