Skip to content

Commit f083d69

Browse files
committed
[Config] Add Kernel method override example for php/xml formats
1 parent 9a386f1 commit f083d69

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)