Merge branch '3.4'
* 3.4: remove useless comment [FrameworkBundle] Make RouterCacheWarmer implement ServiceSubscriberInterface fix merge
This commit is contained in:
commit
4b30b6efc0
@ -91,7 +91,7 @@ class RoutingExtension extends AbstractExtension
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
|
@ -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 @@ use Symfony\Component\Routing\RouterInterface;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @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 @@ class RouterCacheWarmer implements CacheWarmerInterface
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedServices()
|
||||
{
|
||||
return array(
|
||||
'router' => RouterInterface::class,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ abstract class HttpCache extends BaseHttpCache
|
||||
protected function forward(Request $request, $raw = false, Response $entry = null)
|
||||
{
|
||||
$this->getKernel()->boot();
|
||||
$this->getKernel()->getContainer()->set('cache', $this); // to be removed in 4.0?
|
||||
$this->getKernel()->getContainer()->set('cache', $this);
|
||||
|
||||
return parent::forward($request, $raw, $entry);
|
||||
}
|
||||
|
@ -89,8 +89,9 @@
|
||||
<service id="Symfony\Component\Routing\RequestContext" alias="router.request_context" />
|
||||
|
||||
<service id="router.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\RouterCacheWarmer">
|
||||
<tag name="container.service_subscriber" id="router" />
|
||||
<tag name="kernel.cache_warmer" />
|
||||
<argument type="service" id="router" />
|
||||
<argument type="service" id="Psr\Container\ContainerInterface" />
|
||||
</service>
|
||||
|
||||
<service id="router_listener" class="Symfony\Component\HttpKernel\EventListener\RouterListener" public="true">
|
||||
|
@ -1540,10 +1540,6 @@ EOF;
|
||||
} elseif (null !== $reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) {
|
||||
$code = sprintf('$this->get(\'%s\', ContainerInterface::NULL_ON_INVALID_REFERENCE)', $id);
|
||||
} else {
|
||||
if ($this->container->hasAlias($id)) {
|
||||
$id = (string) $this->container->getAlias($id);
|
||||
}
|
||||
|
||||
$code = sprintf('$this->get(\'%s\')', $id);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user