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

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -