You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #34873 [FrameworkBundle] Allow using a ContainerConfigurator in MicroKernelTrait::configureContainer() (nicolas-grekas)
This PR was merged into the 5.1-dev branch.
Discussion
----------
[FrameworkBundle] Allow using a ContainerConfigurator in MicroKernelTrait::configureContainer()
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets | -
| License | MIT
| Doc PR | -
This PR is a continuation of #32937 (it reverts some parts of it that are not needed anymore). It builds on #34872 for now.
This PR allows using the PHP-DSL natively in our `Kernel::configureContainer()` methods.
It allows the same in our `Kernel::configureRoutes()` methods.
Both signatures are handled gracefully with no deprecations to let existing code in peace:
- `protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader);`
- `protected function configureContainer(ContainerConfigurator $c);` (a loader is always passed as 2nd arg to ease FC)
Same for routes:
- `protected function configureRoutes(RoutingConfigurator $routes);`
- `protected function configureRoutes(RouteCollectionBuilder $routes);` (this one is deprecated because `RouteCollectionBuilder` is deprecated)
Here is my working `src/Kernel.php` after this change:
```php
class Kernel extends BaseKernel
{
use MicroKernelTrait;
protected function configureContainer(ContainerConfigurator $container): void
{
$container->import('../config/{packages}/*.yaml');
$container->import('../config/{packages}/'.$this->environment.'/*.yaml');
$container->import('../config/services.yaml');
$container->import('../config/{services}_'.$this->environment.'.yaml');
}
protected function configureRoutes(RoutingConfigurator $routes): void
{
$routes->import('../config/{routes}/'.$this->environment.'/*.yaml');
$routes->import('../config/{routes}/*.yaml');
$routes->import('../config/routes.yaml');
}
}
```
Commits
-------
cf45eec [FrameworkBundle] Allow using a ContainerConfigurator in MicroKernelTrait::configureContainer()
@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);
if (0 !== strpos($e->getMessage(), sprintf('Argument 1 passed to %s::configureContainer() must be an instance of %s,', static::class, ContainerConfigurator::class))) {
@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);
if (0 !== strpos($e->getMessage(), sprintf('Argument 1 passed to %s::configureRoutes() must be an instance of %s,', static::class, RouteCollectionBuilder::class))) {
152
+
throw$e;
153
+
}
140
154
}
141
155
142
-
$file = (new \ReflectionObject($this))->getFileName();
@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);
Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/MicroKernelTraitTest.php
-12Lines changed: 0 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -19,18 +19,6 @@
19
19
20
20
class MicroKernelTraitTest extends TestCase
21
21
{
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.
0 commit comments