Symfony Dependency Injection not triggering load function

一世执手 提交于 2019-12-11 21:18:43

问题


I'm trying out building my own CMS with the Symfony stack and I'm already in some issues with the Dependency Injection.

What am I trying to do
Load the 'Extension' of each module installed on the CMS, so services and doctrine settings can be merged.

What I am doing
Running Symfony Flex ( Symfony 4 ) I have in src/Kernel.php: ( in the configureContainer function)

foreach ($this->getInstalledModules() as $module) {
    $class = 'App\\Modules\\' . $module . '\\DependencyInjection\\' . $module . 'Extension';
    if (class_exists($class)) {
        $container->registerExtension(new $class());
    }
}

I have my modules stored in src/Modules/[module_name], the dependency loader for each module is in src/Modules/[module_name]/DependencyInjection/[module_name]Extension.php with namespace App\Modules\Articles\DependencyInjection

My extension for a module:

class ArticlesExtension extends Extension implements PrependExtensionInterface
{
    public function load(array $configs, ContainerBuilder $container)
    {
        die("LOADING");
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('services.yml');
    }

    public function prepend(ContainerBuilder $container)
    {
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('doctrine.yml');
    }
}

As you can see I added a die for testing purposes, the issue is that this does not get executed ( with or without the die ). The prepend function though gets executed and is working registering my doctrine entities accordingly.

You can find my repository by visiting this link: http://lab.cirykpopeye.be/cirykpopeye/Cirykpopeye.be/tree/development

来源:https://stackoverflow.com/questions/47915952/symfony-dependency-injection-not-triggering-load-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!