2
votes

I obtained this error when I want to create a config paramter to a bundle.

Symfony\Component\DependencyInjection\Exception\InvalidArgumentException] There is no extension able to load the configuration for "mrc_morales_tyre"

This is the code:

app/config/config.yml

mrc_morales_tyre:
    db_driver: orm 

Configuration.php

    namespace MrcMorales\TyreBundle\DependencyInjection;

    use Symfony\Component\Config\Definition\Builder\TreeBuilder;
    use Symfony\Component\Config\Definition\ConfigurationInterface;

    /**
     * This is the class that validates and merges configuration from your app/config files
     *
     * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
     */
    class Configuration implements ConfigurationInterface
    {
        /**
         * {@inheritdoc}
         */
        public function getConfigTreeBuilder()
        {
            $treeBuilder = new TreeBuilder();
            $rootNode = $treeBuilder->root('mrc_morales_tyre');

            $supportedDrivers = array('orm');

            $rootNode
                ->children()
                    ->scalarNode('db_driver')
                        ->validate()
                            ->ifNotInArray($supportedDrivers)
                            ->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers))
                        ->end()
                    ->end()
                ->end();

            return $treeBuilder;        

}
}

TyreExtension.php

namespace MrcMorales\TyreBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Config\Definition\Processor;


/**
 * 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 TyreExtension 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'));
    }
}

TyreBundle.php

namespace MrcMorales\TyreBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use MrcMorales\TyreBundle\DependencyInjection\Compiler\ValidationPass;

class TyreBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        parent::build($container);
        $container->addCompilerPass(new ValidationPass());
    }
}

ValidationPass is to load validation.yml in not usual folder and it works.

Thanks

1
Very strange... have you enabled the bundle in the AppKernel Class correctly? - Matteo
yea! new MrcMorales\TyreBundle\TyreBundle(), - Marc Morales Valldepérez
Can you show us your Bundle.php file? (the one at the root of your bundle) - Snroki
Ok, I edited the question! - Marc Morales Valldepérez
Seems alright... Can you add your config (the file where you put the mrc_morales_tyre configuration) please? That's strange, looks like the DI can't match your config with your bundle - Snroki

1 Answers

0
votes

Resolved:

Symfony by default expects than config var name is the name of extension, in this case tyre.

Then I need to change the Extension name to MrcMoralesTyreExtension but then we need override the method getContainerExtension() in:

TyreBundle.php

   public function getContainerExtension()
    {
        return new MrcMoralesTyreExtension();
    }