I am working on migrating an existing Symfony 2.8
project to Symfony 3.4
. The way how the bundle services are imported are different in these Symfony versions and I wonder what are the pros and cons of the different approaches.
The existing project was build using different bundles where each bundles has its own XYBundle\Resources\services.yml
file and the XYBundle\DependencyInjection\XYExtension.php
file is used to add the service config to the container:
class XYExtension extends Extension {
public function load(array $configs, ContainerBuilder $container) {
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
This way the services defined in XYBundle\Resources\services.yml
become available within the project.
When creating a new Bundle in Symfony 3.4
no extension is created. Instead the services.yml
is added to the apps config.yml
// app/config/config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "@XYBundle/Resources/config/services.yml" }
However, the AppBundle
which was created with the Symfony 3.4
skeleton does not have a services.yml
file at all. Instead all classes within this bundle are automatically made available as service using autowire and autoconfigure within the app/config/services.yml
file.
I am aware that autowire was added in Symfony 3.3
and that it is a great way to automatically add services and add parameters to them. This it is obvious that no XYBundle\Resources\services.yml
file is needed any more when autowire is used.
However, is there any difference in using the "old" extension-way to add/import the bundle services.yml
file and the new way with importing it in app/config/config.yml
?