Skip to content

Commit 0370bd5

Browse files
committed
minor #16694 [Config] Add Kernel method override example for php/xml formats (HypeMC)
This PR was merged into the 5.4 branch. Discussion ---------- [Config] Add Kernel method override example for php/xml formats The docs for version 5.4 aren't clear on what needs to be updated to add support for the `xml` and `php` config formats. With previous versions this wasn't a problem since the `Kernel` class in the recipe had a [`configureContainer` method](https://github.com/symfony/recipes/blob/c88ce965a50fe33073750247066da9d7a23845c1/symfony/framework-bundle/5.3/src/Kernel.php#L14) so it was easy to infer what needs to be done. However, starting with version 5.4 the method was moved to the [`MicroKernelTrait`](https://github.com/symfony/symfony/blob/c9a5155f677c31202770f78921c0afd45be6625c/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php#L50) and [removed from the recipe](https://github.com/symfony/recipes/blob/c88ce965a50fe33073750247066da9d7a23845c1/symfony/framework-bundle/5.4/src/Kernel.php#L10) making it a lot harder to know what exactly needs to be done to get `php`/`xml` formats working. Commits ------- f083d69 [Config] Add Kernel method override example for php/xml formats
2 parents 1695ba7 + f083d69 commit 0370bd5

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

configuration.rst

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,26 @@ shown in these three formats.
6565
Starting from Symfony 5.1, by default Symfony only loads the configuration
6666
files defined in YAML format. If you define configuration in XML and/or PHP
6767
formats, update the ``src/Kernel.php`` file to add support for the ``.xml``
68-
and ``.php`` file extensions.
68+
and ``.php`` file extensions by overriding the
69+
:method:`Symfony\\Component\\HttpKernel\\Kernel::configureContainer` method::
70+
71+
// src/Kernel.php
72+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
73+
74+
private function configureContainer(ContainerConfigurator $container): void
75+
{
76+
$configDir = $this->getConfigDir();
77+
78+
$container->import($configDir.'/{packages}/*.{yaml,php}');
79+
$container->import($configDir.'/{packages}/'.$this->environment.'/*.{yaml,php}');
80+
81+
if (is_file($configDir.'/services.yaml')) {
82+
$container->import($configDir.'/services.yaml');
83+
$container->import($configDir.'/{services}_'.$this->environment.'.yaml');
84+
} else {
85+
$container->import($configDir.'/{services}.php');
86+
}
87+
}
6988

7089
There isn't any practical difference between formats. In fact, Symfony
7190
transforms and caches all of them into PHP before running the application, so

0 commit comments

Comments
 (0)