Symfony Dependency Injection not triggering load f

2019-08-17 18:25发布

问题:

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