Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There is no extension able to load the configuration

Tags:

symfony

I'm trying to load custom config but getting exception:

1/2 InvalidArgumentException in YamlFileLoader.php

There is no extension able to load the configuration for "cwiczenia" (in ..\app/config\config.yml).Looked for namespace "cwiczenia", found "framework", "security",...

2/2 FileLoaderLoadException

There is no extension able to load the configuration for "cwiczenia" ...

..\src\CwiczeniaDependencyInjectionBundle\DependencyInjection\Configuration.php

namespace CwiczeniaDependencyInjectionBundle\DependencyInjection;

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

class Configuration implements ConfigurationInterface{

public function getConfigTreeBuilder()
{
    $treeBuilder = new TreeBuilder();
    $rootNode = $treeBuilder->root('cwiczenia');
    
    $rootNode
        ->children()
            ->scalarNode('teamName')->end()
        ->end();
            
    return $treeBuilder;

..\src\CwiczeniaDependencyInjectionBundle\DependencyInjection\CwiczeniaExtension.php

namespace CwiczeniaDependencyInjectionBundle\DependencyInjection;

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

class CwiczeniaExtension extends Extension
{
    protected function load(array $configs, ContainerBuilder $container) 
    {
        $configuration = $this->getConfiguration($configs, $container);
        $config = $this->processConfiguration($configuration, $configs);
        
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
    }
    public function getAlias()
    {
        return 'cwiczenia';
    }

..\app\config\config.yml

cwiczenia:
    teamName: Lakers

AppKernel

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new AppBundle\AppBundle(),
            new SandersBundle\SandersBundle(),
            new CwiczeniaDependencyInjectionBundle\CwiczeniaDependencyInjectionBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
    }
}

Same exception if I remove Configuration.php

like image 770
Sruj_2ndAccountForStupidQtions Avatar asked Mar 17 '16 00:03

Sruj_2ndAccountForStupidQtions


2 Answers

You have to manually register extension class, how to do it is described here http://symfony.com/doc/current/cookbook/bundles/extension.html#manually-registering-an-extension-class

Something like this:

//.....
class CwiczeniaDependencyInjectionBundle extends Bundle
{

  public function getContainerExtension()
  {
    if (null === $this->extension) {
        $this->extension = new CwiczeniaExtension();
    }
    return $this->extension;
  }
}
like image 54
helios Avatar answered Oct 16 '22 13:10

helios


I had the same problem, and fix it.

To register an extension you need to have same name for bundle and you extension. So, if you wanna enable your extension as cwiczenia, your extension file must be named as CwiczeniaExtention and bundle must be named as CwiczeniaBundle.

Or if you don't wanna change your Bundle name (CwiczeniaDependencyInjectionBundle), you must rename your extension to CwiczeniaDependencyInjectionExtension and then it will be available to load the configuration as cwiczenia_dependency_injection.

Or you can manually register extension, as mentioned above by @helios

like image 2
Sergey Podgornyy Avatar answered Oct 16 '22 13:10

Sergey Podgornyy