php - Processing multiple Symfony bundle configs with one bundle -
i have lots of bundles have similar config files called rules.yml held in bundlename/resources/config/rules.yml each config file follows same structure:
bundle_name: rules: name: items: [] requirements: []
i have 1 bundle called rulerbundle. bundle needs automatically load, validate , combine rules.yml found within other bundles. rulerbundle produce like:
bundle_a: rules: name: rule 1 items: ['first item'] requirements: ['second item', 'third item'] bundle_b: rules: name: rule 2 items: ['second item'] requirements: ['third item']
this should automatically updated when new bundle added rules.yml
questions
should validate , process config within every bundle? lead code duplication validation rules same.
how go finding , merging each of bundle configs rulerbundle
so can write dependencyinjection extension in top level bundle of validation. not sure should happen if invalid this:
// src/bundlename/dependencyinjection/bundleextension.php namespace acme\hellobundle\dependencyinjection; use symfony\component\httpkernel\dependencyinjection\extension; use symfony\component\dependencyinjection\extension\prependextensioninterface; use symfony\component\dependencyinjection\containerbuilder; class bundlename extends extension implements prependextensioninterface { public function prepend(containerbuilder $container) { $bundles = $container->getparameter('kernel.bundles'); foreach ($bundles $name => $extension) { $loader = new loader\yamlfileloader($container, new filelocator(__dir__.$name.'/../../resources/config')); // load configuration file, returned array $config = $loader->loadfile('rules.yml'); // validate contents of file $this->validateconfig($config); // append config specified bundle name "bundle_a", "bundle_a" $container->prependextensionconfig($name, $config); } } }
haven't tested of base idea. you'll need implement config validation method.
Comments
Post a Comment