Here's how to do it.
Create the services.yml file in your bundle, probably in something like /src/Acme/DemoBundle/Resources/config/services.yml
Next, edit the bundle's extension file and change which services file gets loaded:
// src/Acme/DemoBundle/DependencyInjection/AcmeDemoExtension.php
namespace Acme\DemoBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
class AcmeDemoExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
public function getAlias()
{
return 'acme_demo';
}
}
The main changes are:- switching the XmlFileLoader to YamlFileLoader in line 14
- canging the file to services.yml in line 15
You also need to change the "use" statement line 6 :
ReplyDeleteuse Symfony\Component\DependencyInjection\Loader\XmlFileLoader; in
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Thanks. Updated.
ReplyDeleteHi!
ReplyDeleteWhy did you decided to migrate from XML to YML definition?
Aesthetic of the services definition?
Thanks!