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

Commit0bb19b7

Browse files
committed
[FrameworkBundle][Routing] Add a new tag to be able to use a private service as a service route loader
1 parentb82b09e commit0bb19b7

File tree

10 files changed

+182
-3
lines changed

10 files changed

+182
-3
lines changed

‎UPGRADE-4.3.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ Routing
123123
options have been deprecated.
124124
* Implementing `Serializable` for `Route` and `CompiledRoute` is deprecated; if you serialize them, please
125125
ensure your unserialization logic can recover from a failure related to an updated serialization format
126+
* Not tagging the route loader services with `routing.router_loader` has been deprecated.
126127

127128
Security
128129
--------

‎UPGRADE-5.0.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ Routing
284284
options have been removed.
285285
* `Route` and `CompiledRoute` don't implement `Serializable` anymore; if you serialize them, please
286286
ensure your unserialization logic can recover from a failure related to an updated serialization format
287+
* The route loader services must be tagged with `routing.router_loader`.
287288

288289
Security
289290
--------

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class UnusedTagsPass implements CompilerPassInterface
4949
'proxy',
5050
'routing.expression_language_provider',
5151
'routing.loader',
52+
'routing.router_loader',
5253
'security.expression_language_provider',
5354
'security.remember_me_aware',
5455
'security.voter',

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
useSymfony\Component\Routing\Generator\UrlGenerator;
9393
useSymfony\Component\Routing\Loader\AnnotationDirectoryLoader;
9494
useSymfony\Component\Routing\Loader\AnnotationFileLoader;
95+
useSymfony\Component\Routing\Loader\DependencyInjection\ServiceRouterLoaderInterface;
9596
useSymfony\Component\Routing\Matcher\CompiledUrlMatcher;
9697
useSymfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
9798
useSymfony\Component\Security\Core\Security;
@@ -428,6 +429,9 @@ public function load(array $configs, ContainerBuilder $container)
428429
if (!$config['disallow_search_engine_index'] ??false) {
429430
$container->removeDefinition('disallow_search_engine_index_response_listener');
430431
}
432+
433+
$container->registerForAutoconfiguration(ServiceRouterLoaderInterface::class)
434+
->addTag('routing.router_loader');
431435
}
432436

433437
/**

‎src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,23 @@ public function registerContainerConfiguration(LoaderInterface $loader)
6969
],
7070
]);
7171

72-
if ($thisinstanceof EventSubscriberInterface) {
72+
if (!$container->hasDefinition('kernel')) {
7373
$container->register('kernel',static::class)
7474
->setSynthetic(true)
7575
->setPublic(true)
76-
->addTag('kernel.event_subscriber')
7776
;
7877
}
7978

79+
$kernelDefinition =$container->getDefinition('kernel');
80+
81+
$kernelDefinition->addTag('routing.router_loader', [
82+
'service_id' =>'kernel',
83+
]);
84+
85+
if ($thisinstanceof EventSubscriberInterface) {
86+
$kernelDefinition->addTag('kernel.event_subscriber');
87+
}
88+
8089
$this->configureContainer($container,$loader);
8190

8291
$container->addObjectResource($this);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@
4040
<argumenttype="service"id="file_locator" />
4141
</service>
4242

43+
<serviceid="routing.loader.service.container"class="Symfony\Component\Routing\Loader\DependencyInjection\ServiceRouterLoaderContainer">
44+
<argumenttype="service"id="service_container" />
45+
<argumenttype="tagged_locator"tag="routing.router_loader"index-by="service_id" />
46+
</service>
47+
4348
<serviceid="routing.loader.service"class="Symfony\Component\Routing\Loader\DependencyInjection\ServiceRouterLoader">
4449
<tagname="routing.loader" />
45-
<argumenttype="service"id="service_container" />
50+
<argumenttype="service"id="routing.loader.service.container" />
4651
</service>
4752

4853
<serviceid="routing.loader"class="Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader"public="true">

‎src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
namespaceSymfony\Bundle\FrameworkBundle\Tests\Kernel;
1313

1414
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\DependencyInjection\ContainerBuilder;
16+
useSymfony\Component\DependencyInjection\Extension\ExtensionInterface;
17+
useSymfony\Component\DependencyInjection\Loader\ClosureLoader;
1518
useSymfony\Component\HttpFoundation\Request;
1619

1720
class MicroKernelTraitTestextends TestCase
@@ -39,4 +42,21 @@ public function testAsEventSubscriber()
3942

4043
$this->assertSame('It\'s dangerous to go alone. Take this ⚔',$response->getContent());
4144
}
45+
46+
publicfunctiontestRoutingRouteLoaderTagIsAdded()
47+
{
48+
$frameworkExtension =$this->createMock(ExtensionInterface::class);
49+
$frameworkExtension
50+
->expects($this->atLeastOnce())
51+
->method('getAlias')
52+
->willReturn('framework');
53+
54+
$container =newContainerBuilder();
55+
$container->registerExtension($frameworkExtension);
56+
57+
$kernel =newConcreteMicroKernel('test',false);
58+
$kernel->registerContainerConfiguration(newClosureLoader($container));
59+
60+
$this->assertTrue($container->getDefinition('kernel')->hasTag('routing.router_loader'));
61+
}
4262
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Routing\Loader\DependencyInjection;
13+
14+
usePsr\Container\ContainerInterface;
15+
16+
/**
17+
* @internal
18+
*
19+
* @deprecated since Symfony 4.3, to be removed in 5.0
20+
*/
21+
class ServiceRouterLoaderContainerimplements ContainerInterface
22+
{
23+
private$container;
24+
private$serviceLocator;
25+
26+
publicfunction__construct(ContainerInterface$container,ContainerInterface$serviceLocator)
27+
{
28+
$this->container =$container;
29+
$this->serviceLocator =$serviceLocator;
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
publicfunctionget($id)
36+
{
37+
if ($this->serviceLocator->has($id)) {
38+
return$this->serviceLocator->get($id);
39+
}
40+
41+
@trigger_error(sprintf('Registering the routing loader "%s" without tagging it with the "routing.router_loader" tag is deprecated since Symfony 4.3 and will be required in Symfony 5.0.',$id),E_USER_DEPRECATED);
42+
43+
return$this->container->get($id);
44+
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
publicfunctionhas($id)
50+
{
51+
return$this->serviceLocator->has($id) ||$this->container->has($id);
52+
}
53+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Routing\Loader\DependencyInjection;
13+
14+
/**
15+
* Marker interface for route loader services.
16+
*/
17+
interface ServiceRouterLoaderInterface
18+
{
19+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Routing\Tests\Loader;
13+
14+
usePHPUnit\Framework\TestCase;
15+
usePsr\Container\ContainerInterface;
16+
useSymfony\Component\DependencyInjection\Container;
17+
useSymfony\Component\Routing\Loader\DependencyInjection\ServiceRouterLoaderContainer;
18+
19+
class ServiceRouterLoaderContainerTestextends TestCase
20+
{
21+
/**
22+
* @var ContainerInterface
23+
*/
24+
private$container;
25+
26+
/**
27+
* @var ContainerInterface
28+
*/
29+
private$serviceLocator;
30+
31+
/**
32+
* @var ServiceRouterLoaderContainer
33+
*/
34+
private$serviceRouterLoaderContainer;
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
protectedfunctionsetUp()
40+
{
41+
$this->container =newContainer();
42+
$this->container->set('foo',new \stdClass());
43+
44+
$this->serviceLocator =newContainer();
45+
$this->serviceLocator->set('bar',new \stdClass());
46+
47+
$this->serviceRouterLoaderContainer =newServiceRouterLoaderContainer($this->container,$this->serviceLocator);
48+
}
49+
50+
/**
51+
* @group legacy
52+
* @expectedDeprecation Registering the routing loader "foo" without tagging it with the "routing.router_loader" tag is deprecated since Symfony 4.3 and will be required in Symfony 5.0.
53+
*/
54+
publicfunctiontestGet()
55+
{
56+
$this->assertSame($this->container->get('foo'),$this->serviceRouterLoaderContainer->get('foo'));
57+
$this->assertSame($this->serviceLocator->get('bar'),$this->serviceRouterLoaderContainer->get('bar'));
58+
}
59+
60+
publicfunctiontestHas()
61+
{
62+
$this->assertTrue($this->serviceRouterLoaderContainer->has('foo'));
63+
$this->assertTrue($this->serviceRouterLoaderContainer->has('bar'));
64+
$this->assertFalse($this->serviceRouterLoaderContainer->has('ccc'));
65+
}
66+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp