When reorganizing my bundles, I decided to load my services from my bundle dependency injection.
My bundle name is “UserBundle” and my vendor name “xxx”.
So, I created an extension file from my bundle called “xxxUserExtension.php” in “UserBundle/DependencyInjection/”
This was my content file:
<?php namespace xxx\UserBundle\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; /** * This is the class that loads and manages your bundle configuration * * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} */ class xxxUserExtension extends Extension { /** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('user.yml'); $loader->load('forms.yml'); $loader->load('validation.xml'); } }
And of course, I’ve got this error:
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException] Unable to parse file "C:\wamp\www\xxx\src\Headoo\UserBundle\DependencyInjection/../Resources/config\user.yml".
Maybe you want to know the cause, right?
This error simply occured because I was loading an yml file with an xmlFileLoader. Also, i was loading an xml file, we never have to load two different file types with a single file type loader.
Look here:
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('user.yml'); $loader->load('forms.yml'); $loader->load('validation.xml');
So to solve this error, you have to use only one extension for your services and choose the correct loader.
This is the correct file:
<?php namespace xxx\UserBundle\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; /** * This is the class that loads and manages your bundle configuration * * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} */ class xxxUserExtension extends Extension { /** * {@inheritDoc} */ 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('user.yml'); $loader->load('forms.yml'); } }
Hope, this helped.