user3886650 user3886650 - 3 months ago 19
PHP Question

Symfony loading a custom config array

Say I have an array like this in a custom array.yml in Bundle/Resources/config

array
array
value
value
value
array
array
value
value
value


Is there a quick and dirty way I can load it without having to use that cumbersome treebuilder?

Answer

Seems like the easiest way is to directly set the parameter in the container

class BundleExtension extends Extension
{

    public function load(array $configs, ContainerBuilder $container)
    {
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));

        $loader->load('services.yml');

        $config = Yaml::parse(file_get_contents(__DIR__."/../Resources/config/array.yml"));
        $container->setParameter("bundle.array",$config);

    }
}
Comments