Skip to content

Commit 5d8595b

Browse files
committed
[FrameworkBundle][Routing] Private service route loaders
1 parent 40fe161 commit 5d8595b

File tree

11 files changed

+177
-3
lines changed

11 files changed

+177
-3
lines changed

UPGRADE-4.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ FrameworkBundle
8686
* The `ControllerResolver` and `DelegatingLoader` classes have been marked as `final`.
8787
* The `controller_name_converter` and `resolve_controller_name_subscriber` services have been deprecated.
8888
* Deprecated `routing.loader.service`, use `routing.loader.container` instead.
89+
* Not tagging service route loaders with `routing.route_loader` has been deprecated.
8990

9091
HttpClient
9192
----------

UPGRADE-5.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ Routing
368368
* `Serializable` implementing methods for `Route` and `CompiledRoute` are final.
369369
Instead of overwriting them, use `__serialize` and `__unserialize` as extension points which are forward compatible
370370
with the new serialization methods in PHP 7.4.
371+
* Service route loaders must be tagged with `routing.route_loader`.
371372

372373
Security
373374
--------

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* Added support for configuring chained cache pools
1212
* Deprecated booting the kernel before running `WebTestCase::createClient()`
1313
* Deprecated `routing.loader.service`, use `routing.loader.container` instead.
14+
* Not tagging service route loaders with `routing.route_loader` has been deprecated.
1415

1516
4.3.0
1617
-----

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.route_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
@@ -24,6 +24,7 @@
2424
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2525
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
2626
use Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher;
27+
use Symfony\Bundle\FrameworkBundle\Routing\RouteLoaderInterface;
2728
use Symfony\Bundle\FullStack;
2829
use Symfony\Component\Asset\PackageInterface;
2930
use Symfony\Component\BrowserKit\AbstractBrowser;
@@ -446,6 +447,9 @@ public function load(array $configs, ContainerBuilder $container)
446447
if (!$config['disallow_search_engine_index'] ?? false) {
447448
$container->removeDefinition('disallow_search_engine_index_response_listener');
448449
}
450+
451+
$container->registerForAutoconfiguration(RouteLoaderInterface::class)
452+
->addTag('routing.route_loader');
449453
}
450454

451455
/**

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

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

72-
if ($this instanceof 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+
$kernelDefinition->addTag('routing.route_loader');
81+
82+
if ($this instanceof EventSubscriberInterface) {
83+
$kernelDefinition->addTag('kernel.event_subscriber');
84+
}
85+
8086
$this->configureContainer($container, $loader);
8187

8288
$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
@@ -47,7 +47,12 @@
4747

4848
<service id="routing.loader.container" class="Symfony\Component\Routing\Loader\ContainerLoader">
4949
<tag name="routing.loader" />
50-
<argument type="service" id="service_container" />
50+
<argument type="service">
51+
<service class="Symfony\Bundle\FrameworkBundle\Routing\LegacyRouteLoaderContainer">
52+
<argument type="service" id="service_container" />
53+
<argument type="tagged_locator" tag="routing.route_loader" />
54+
</service>
55+
</argument>
5156
</service>
5257

5358
<service id="routing.loader" class="Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader" public="true">
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
namespace Symfony\Bundle\FrameworkBundle\Routing;
13+
14+
use Psr\Container\ContainerInterface;
15+
16+
/**
17+
* @internal to be removed in Symfony 5.0
18+
*/
19+
class LegacyRouteLoaderContainer implements ContainerInterface
20+
{
21+
private $container;
22+
private $serviceLocator;
23+
24+
public function __construct(ContainerInterface $container, ContainerInterface $serviceLocator)
25+
{
26+
$this->container = $container;
27+
$this->serviceLocator = $serviceLocator;
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function get($id)
34+
{
35+
if ($this->serviceLocator->has($id)) {
36+
return $this->serviceLocator->get($id);
37+
}
38+
39+
@trigger_error(sprintf('Registering the service route loader "%s" without tagging it with the "routing.route_loader" tag is deprecated since Symfony 4.4 and will be required in Symfony 5.0.', $id), E_USER_DEPRECATED);
40+
41+
return $this->container->get($id);
42+
}
43+
44+
/**
45+
* {@inheritdoc}
46+
*/
47+
public function has($id)
48+
{
49+
return $this->serviceLocator->has($id) || $this->container->has($id);
50+
}
51+
}
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+
namespace Symfony\Bundle\FrameworkBundle\Routing;
13+
14+
/**
15+
* Marker interface for service route loaders.
16+
*/
17+
interface RouteLoaderInterface
18+
{
19+
}

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

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

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

1720
class MicroKernelTraitTest extends TestCase
@@ -39,4 +42,18 @@ public function testAsEventSubscriber()
3942

4043
$this->assertSame('It\'s dangerous to go alone. Take this ⚔', $response->getContent());
4144
}
45+
46+
public function testRoutingRouteLoaderTagIsAdded()
47+
{
48+
$frameworkExtension = $this->createMock(ExtensionInterface::class);
49+
$frameworkExtension
50+
->expects($this->atLeastOnce())
51+
->method('getAlias')
52+
->willReturn('framework');
53+
$container = new ContainerBuilder();
54+
$container->registerExtension($frameworkExtension);
55+
$kernel = new ConcreteMicroKernel('test', false);
56+
$kernel->registerContainerConfiguration(new ClosureLoader($container));
57+
$this->assertTrue($container->getDefinition('kernel')->hasTag('routing.route_loader'));
58+
}
4259
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy