Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4758a06

Browse files
[FrameworkBundle] Make RouterCacheWarmer implement ServiceSubscriberInterface
1 parentab661bd commit4758a06

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

‎src/Symfony/Bridge/Twig/Extension/RoutingExtension.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function getUrl($name, $parameters = array(), $schemeRelative = false)
9191
*
9292
* @return array An array with the contexts the URL is safe
9393
*
94-
*To be made@finalin3.4,and thetype-hint be changedto"\Twig\Node\Node" in 4.0.
94+
* @finalsince version3.4, type-hinttobe changed "\Twig\Node\Node" in 4.0
9595
*/
9696
publicfunctionisUrlGenerationSafe(\Twig_Node$argsNode)
9797
{

‎src/Symfony/Bundle/FrameworkBundle/CacheWarmer/RouterCacheWarmer.php‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespaceSymfony\Bundle\FrameworkBundle\CacheWarmer;
1313

14+
usePsr\Container\ContainerInterface;
15+
useSymfony\Component\DependencyInjection\ServiceSubscriberInterface;
1416
useSymfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
1517
useSymfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
1618
useSymfony\Component\Routing\RouterInterface;
@@ -20,20 +22,28 @@
2022
*
2123
* @author Fabien Potencier <fabien@symfony.com>
2224
*
23-
* @final since version 3.4, to be given a container instead in 4.0
25+
* @final since version 3.4
2426
*/
25-
class RouterCacheWarmerimplements CacheWarmerInterface
27+
class RouterCacheWarmerimplements CacheWarmerInterface, ServiceSubscriberInterface
2628
{
2729
protected$router;
2830

2931
/**
3032
* Constructor.
3133
*
32-
* @paramRouterInterface $router A Router instance
34+
* @paramContainerInterface $container
3335
*/
34-
publicfunction__construct(RouterInterface$router)
36+
publicfunction__construct($container)
3537
{
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__));
46+
}
3747
}
3848

3949
/**
@@ -57,4 +67,14 @@ public function isOptional()
5767
{
5868
returntrue;
5969
}
70+
71+
/**
72+
* {@inheritdoc}
73+
*/
74+
publicstaticfunctiongetSubscribedServices()
75+
{
76+
returnarray(
77+
'router' => RouterInterface::class,
78+
);
79+
}
6080
}

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@
9797
<serviceid="Symfony\Component\Routing\RequestContext"alias="router.request_context" />
9898

9999
<serviceid="router.cache_warmer"class="Symfony\Bundle\FrameworkBundle\CacheWarmer\RouterCacheWarmer">
100+
<tagname="container.service_subscriber"id="router" />
100101
<tagname="kernel.cache_warmer" />
101-
<argumenttype="service"id="router" />
102+
<argumenttype="service"id="Psr\Container\ContainerInterface" />
102103
</service>
103104

104105
<serviceid="router_listener"class="Symfony\Component\HttpKernel\EventListener\RouterListener"public="true">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp