php - Get Symfony2 environment in bundle Extension -
in symfony2 bundle extension services.yml being loaded
$loader = new loader\yamlfileloader($container, new filelocator(__dir__ . '/../resources/config')); $loader->load('services.yml'); however want load different services config per environment (eg: different 1 tests).
most of examples i've found getting current environment access within controllers (eg: $this->get('kernel')->getenvironment()), controller based access not possible in extensions.
according twig extension - symfony2 environment environment can constructor injected i'm not sure how bundle extension registered/instantiated symfony not sure how have enviroment injected (the references find via grep in cache files, isn't helpful).
how can either specify different services yaml file loaded per env in config, or @ least find out environment can code extension class load correct file?
normally, while loading services, method prototype should
public function load(array $configs, containerbuilder $container). then can access environment doing
$env = $container->getparameter("kernel.environment") and test $env see in environment type are.
something like
if ("dev" == $env) { $loader = new loader\yamlfileloader($container, new filelocator(__dir__.'/../resources/config')); $loader->load('devservices.yml'); } ... hope helps!
Comments
Post a Comment