Skip to content

[Config] Add Kernel method override example for php/xml formats #16694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,26 @@ shown in these three formats.
Starting from Symfony 5.1, by default Symfony only loads the configuration
files defined in YAML format. If you define configuration in XML and/or PHP
formats, update the ``src/Kernel.php`` file to add support for the ``.xml``
and ``.php`` file extensions.
and ``.php`` file extensions by overriding the
:method:`Symfony\\Component\\HttpKernel\\Kernel::configureContainer` method::

// src/Kernel.php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

private function configureContainer(ContainerConfigurator $container): void
{
$configDir = $this->getConfigDir();

$container->import($configDir.'/{packages}/*.{yaml,php}');
$container->import($configDir.'/{packages}/'.$this->environment.'/*.{yaml,php}');

if (is_file($configDir.'/services.yaml')) {
$container->import($configDir.'/services.yaml');
$container->import($configDir.'/{services}_'.$this->environment.'.yaml');
} else {
$container->import($configDir.'/{services}.php');
}
}

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