How to load, process and use custom parameters from Yaml configuration files in DI Extension class?

你离开我真会死。 提交于 2019-12-03 07:48:53
gp_sflover

If you want to load a custom configuration file to process it's parameters using an Extension class (like in Symfony bundle extension but without to create a bundle), to eventually "create" and add one or more of it to the "container" (before it will be compiled) you can register your Extension class manually in the configureContainer method contained in the Kernel.php file:

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
{
    // to avoid the same error you need to put this line at the top
    // if your file is stored under "$this->getProjectDir().'/config'" directory
    $container->registerExtension(new YourAppExtensionClass());

    // ----- rest of the code
}

Then you can use your params as usual registering a Compiler Pass.

Hope this helps.

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