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

Appearance settings

Commit b690a6d

Browse filesBrowse files
[FrameworkBundle] Allow using a ContainerConfigurator in MicroKernelTrait::configureContainer()
1 parent 3409955 commit b690a6d
Copy full SHA for b690a6d

File tree

11 files changed

+57
-171
lines changed
Filter options

11 files changed

+57
-171
lines changed

‎UPGRADE-5.1.md

Copy file name to clipboardExpand all lines: UPGRADE-5.1.md
-6Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
UPGRADE FROM 5.0 to 5.1
22
=======================
33

4-
FrameworkBundle
5-
---------------
6-
7-
* Marked `MicroKernelTrait::configureRoutes()` as `@internal` and `@final`.
8-
* Deprecated not overriding `MicroKernelTrait::configureRouting()`.
9-
104
HttpFoundation
115
--------------
126

‎UPGRADE-6.0.md

Copy file name to clipboardExpand all lines: UPGRADE-6.0.md
-6Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
UPGRADE FROM 5.x to 6.0
22
=======================
33

4-
FrameworkBundle
5-
---------------
6-
7-
* Removed `MicroKernelTrait::configureRoutes()`.
8-
* Made `MicroKernelTrait::configureRouting()` abstract.
9-
104
HttpFoundation
115
--------------
126

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ CHANGELOG
44
5.1.0
55
-----
66

7-
* Marked `MicroKernelTrait::configureRoutes()` as `@internal` and `@final`.
8-
* Deprecated not overriding `MicroKernelTrait::configureRouting()`.
7+
* Made `MicroKernelTrait::configureContainer()` compatible with `ContainerConfigurator`
8+
* Made `MicroKernelTrait::configureRoutes()` compatible with `RoutingConfigurator`
99
* Added a new `mailer.message_bus` option to configure or disable the message bus to use to send mails.
1010
* Added flex-based default implementation for `MicroKernelTrait::registerBundles()`
1111

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php
+45-33Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
use Symfony\Component\Config\Loader\LoaderInterface;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
1617
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1718
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
19+
use Symfony\Component\Routing\RouteCollection;
1820
use Symfony\Component\Routing\RouteCollectionBuilder;
1921

2022
/**
@@ -25,20 +27,6 @@
2527
*/
2628
trait MicroKernelTrait
2729
{
28-
/**
29-
* Add or import routes into your application.
30-
*
31-
* $routes->import('config/routing.yml');
32-
* $routes->add('/admin', 'App\Controller\AdminController::dashboard', 'admin_dashboard');
33-
*
34-
* @final since Symfony 5.1, override configureRouting() instead
35-
*
36-
* @internal since Symfony 5.1, use configureRouting() instead
37-
*/
38-
protected function configureRoutes(RouteCollectionBuilder $routes)
39-
{
40-
}
41-
4230
/**
4331
* Adds or imports routes into your application.
4432
*
@@ -48,29 +36,26 @@ protected function configureRoutes(RouteCollectionBuilder $routes)
4836
* ->controller('App\Controller\AdminController::dashboard')
4937
* ;
5038
*/
51-
protected function configureRouting(RoutingConfigurator $routes): void
52-
{
53-
@trigger_error(sprintf('Not overriding the "%s()" method is deprecated since Symfony 5.1 and will trigger a fatal error in 6.0.', __METHOD__), E_USER_DEPRECATED);
54-
}
39+
abstract protected function configureRoutes(RoutingConfigurator $routes);
5540

5641
/**
5742
* Configures the container.
5843
*
5944
* You can register extensions:
6045
*
61-
* $c->loadFromExtension('framework', [
46+
* $c->extension('framework', [
6247
* 'secret' => '%secret%'
6348
* ]);
6449
*
6550
* Or services:
6651
*
67-
* $c->register('halloween', 'FooBundle\HalloweenProvider');
52+
* $c->services()->set('halloween', 'FooBundle\HalloweenProvider');
6853
*
6954
* Or parameters:
7055
*
71-
* $c->setParameter('halloween', 'lot of fun');
56+
* $c->parameters()->set('halloween', 'lot of fun');
7257
*/
73-
abstract protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader);
58+
abstract protected function configureContainer(ContainerConfigurator $c);
7459

7560
/**
7661
* {@inheritdoc}
@@ -112,13 +97,31 @@ public function registerContainerConfiguration(LoaderInterface $loader)
11297
$kernelDefinition->addTag('kernel.event_subscriber');
11398
}
11499

100+
$container->addObjectResource($this);
115101
$container->fileExists($this->getProjectDir().'/config/bundles.php');
116102
$container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || !ini_get('opcache.preload'));
117103
$container->setParameter('container.dumper.inline_factories', true);
118104

119-
$this->configureContainer($container, $loader);
120-
121-
$container->addObjectResource($this);
105+
try {
106+
$this->configureContainer($container, $loader);
107+
} catch (\TypeError $e) {
108+
$file = $e->getFile();
109+
110+
if (0 !== strpos($e->getMessage(), sprintf('Argument 1 passed to %s::configureContainer() must be an instance of %s,', static::class, ContainerConfigurator::class))) {
111+
throw $e;
112+
}
113+
114+
$kernelLoader = $loader->getResolver()->resolve($file);
115+
$kernelLoader->setCurrentDir(\dirname($file));
116+
$instanceof = &\Closure::bind(function &() { return $this->instanceof; }, $kernelLoader, $kernelLoader)();
117+
118+
try {
119+
$this->configureContainer(new ContainerConfigurator($container, $kernelLoader, $instanceof, $file, $file), $loader);
120+
} finally {
121+
$instanceof = [];
122+
$kernelLoader->registerAliasesForSinglyImplementedInterfaces();
123+
}
124+
}
122125
});
123126
}
124127

@@ -127,17 +130,26 @@ public function registerContainerConfiguration(LoaderInterface $loader)
127130
*/
128131
public function loadRoutes(LoaderInterface $loader)
129132
{
130-
$routes = new RouteCollectionBuilder($loader);
131-
$this->configureRoutes($routes);
132-
$collection = $routes->build();
133+
$file = (new \ReflectionObject($this))->getFileName();
134+
$kernelLoader = $loader->getResolver()->resolve($file);
135+
$kernelLoader->setCurrentDir(\dirname($file));
136+
$collection = new RouteCollection();
137+
138+
try {
139+
$this->configureRoutes(new RoutingConfigurator($collection, $kernelLoader, $file, $file));
133140

134-
if (0 !== \count($collection)) {
135-
@trigger_error(sprintf('Adding routes via the "%s:configureRoutes()" method is deprecated since Symfony 5.1 and will have no effect in 6.0; use "configureRouting()" instead.', self::class), E_USER_DEPRECATED);
141+
return $collection;
142+
} catch (\TypeError $e) {
143+
if (0 !== strpos($e->getMessage(), sprintf('Argument 1 passed to %s::configureRoutes() must be an instance of %s,', static::class, RouteCollectionBuilder::class))) {
144+
throw $e;
145+
}
136146
}
137147

138-
$file = (new \ReflectionObject($this))->getFileName();
139-
$this->configureRouting(new RoutingConfigurator($collection, $loader, null, $file));
148+
@trigger_error(sprintf('Using type "%s" for argument 1 of method "%s:configureRoutes()" is deprecated since Symfony 5.1, use "%s" instead.', RouteCollectionBuilder::class, self::class, RoutingConfigurator::class), E_USER_DEPRECATED);
149+
150+
$routes = new RouteCollectionBuilder($loader);
151+
$this->configureRoutes($routes);
140152

141-
return $collection;
153+
return $routes->build();
142154
}
143155
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/ConcreteMicroKernel.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function __destruct()
8080
$fs->remove($this->cacheDir);
8181
}
8282

83-
protected function configureRouting(RoutingConfigurator $routes): void
83+
protected function configureRoutes(RoutingConfigurator $routes): void
8484
{
8585
$routes->add('halloween', '/')->controller('kernel::halloweenAction');
8686
$routes->add('danger', '/danger')->controller('kernel::dangerousAction');

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php
-12Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@
1919

2020
class MicroKernelTraitTest extends TestCase
2121
{
22-
/**
23-
* @group legacy
24-
* @expectedDeprecation Adding routes via the "Symfony\Bundle\FrameworkBundle\Tests\Kernel\MicroKernelWithConfigureRoutes:configureRoutes()" method is deprecated since Symfony 5.1 and will have no effect in 6.0; use "configureRouting()" instead.
25-
* @expectedDeprecation Not overriding the "Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait::configureRouting()" method is deprecated since Symfony 5.1 and will trigger a fatal error in 6.0.
26-
*/
27-
public function testConfigureRoutingDeprecated()
28-
{
29-
$kernel = new MicroKernelWithConfigureRoutes('test', false);
30-
$kernel->boot();
31-
$kernel->handle(Request::create('/'));
32-
}
33-
3422
public function test()
3523
{
3624
$kernel = new ConcreteMicroKernel('test', false);

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelWithConfigureRoutes.php
-74Lines changed: 0 additions & 74 deletions
This file was deleted.

‎src/Symfony/Bundle/FrameworkBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"symfony/polyfill-mbstring": "~1.0",
2828
"symfony/filesystem": "^4.4|^5.0",
2929
"symfony/finder": "^4.4|^5.0",
30-
"symfony/routing": "^5.1"
30+
"symfony/routing": "^5.0"
3131
},
3232
"require-dev": {
3333
"doctrine/annotations": "~1.7",

‎src/Symfony/Component/Routing/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/CHANGELOG.md
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ CHANGELOG
55
-----
66

77
* Deprecated `RouteCollectionBuilder` in favor of `RoutingConfigurator`.
8-
* Added support for a generic loader to `RoutingConfigurator`.
98

109
5.0.0
1110
-----

‎src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php
+5-35Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
namespace Symfony\Component\Routing\Loader\Configurator;
1313

14-
use Symfony\Component\Config\Exception\LoaderLoadException;
15-
use Symfony\Component\Config\Loader\FileLoader;
16-
use Symfony\Component\Config\Loader\LoaderInterface;
14+
use Symfony\Component\Routing\Loader\PhpFileLoader;
1715
use Symfony\Component\Routing\RouteCollection;
1816

1917
/**
@@ -27,7 +25,7 @@ class RoutingConfigurator
2725
private $path;
2826
private $file;
2927

30-
public function __construct(RouteCollection $collection, LoaderInterface $loader, ?string $path, string $file)
28+
public function __construct(RouteCollection $collection, PhpFileLoader $loader, string $path, string $file)
3129
{
3230
$this->collection = $collection;
3331
$this->loader = $loader;
@@ -40,7 +38,9 @@ public function __construct(RouteCollection $collection, LoaderInterface $loader
4038
*/
4139
final public function import($resource, string $type = null, bool $ignoreErrors = false, $exclude = null): ImportConfigurator
4240
{
43-
$imported = $this->load($resource, $type, $ignoreErrors, $exclude) ?: [];
41+
$this->loader->setCurrentDir(\dirname($this->path));
42+
43+
$imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file, $exclude) ?: [];
4444
if (!\is_array($imported)) {
4545
return new ImportConfigurator($this->collection, $imported);
4646
}
@@ -57,34 +57,4 @@ final public function collection(string $name = ''): CollectionConfigurator
5757
{
5858
return new CollectionConfigurator($this->collection, $name);
5959
}
60-
61-
/**
62-
* @param string|string[]|null $exclude
63-
*
64-
* @return RouteCollection|RouteCollection[]|null
65-
*/
66-
private function load($resource, ?string $type, bool $ignoreErrors, $exclude)
67-
{
68-
$loader = $this->loader;
69-
70-
if (!$loader->supports($resource, $type)) {
71-
if (null === $resolver = $loader->getResolver()) {
72-
throw new LoaderLoadException($resource, $this->file, null, null, $type);
73-
}
74-
75-
if (false === $loader = $resolver->resolve($resource, $type)) {
76-
throw new LoaderLoadException($resource, $this->file, null, null, $type);
77-
}
78-
}
79-
80-
if (!$loader instanceof FileLoader) {
81-
return $loader->load($resource, $type);
82-
}
83-
84-
if (null !== $this->path) {
85-
$this->loader->setCurrentDir(\dirname($this->path));
86-
}
87-
88-
return $this->loader->import($resource, $type, $ignoreErrors, $this->file, $exclude);
89-
}
9060
}

‎src/Symfony/Component/Routing/RouteCollectionBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/RouteCollectionBuilder.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Symfony\Component\Config\Exception\LoaderLoadException;
1515
use Symfony\Component\Config\Loader\LoaderInterface;
1616
use Symfony\Component\Config\Resource\ResourceInterface;
17+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
18+
19+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 5.1, use "%s" instead.', RouteCollectionBuilder::class, RoutingConfigurator::class), E_USER_DEPRECATED);
1720

1821
/**
1922
* Helps add and import routes into a RouteCollection.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.