symfony - How to add a setter injection injecting a service from a bundle extension -


i'm trying make kind of optional dependency on doctrine orm. depending on configuration, want "doctrine.orm.entity_manager" injected setter injection alsatian_form.form_event_subscriber.extensible service.

<?php  use symfony\component\httpkernel\dependencyinjection\extension;  class alsatianformextension extends extension {     public function load(array $configs, containerbuilder $container)     {         $configuration = new configuration();         $configformbundle = $this->processconfiguration($configuration, $configs);         $loader = new loader\yamlfileloader($container, new filelocator(__dir__.'/../resources/config'));         $loader->load('services.yml');           if($configformbundle['extensible_entity']['enabled']){             $definition = $container->getdefinition('alsatian_form.form_type.extensible_entity');             $definition->setpublic(true);             $definition->addtag('form.type');              $container->getdefinition('alsatian_form.form_event_subscriber.extensible')                 ->addmethodcall('setentitymanager', array("@doctrine.orm.entity_manager")); // <- here tried same syntax in yaml configuration files.         }     } } 

i think must syntax problem, because receive string '@doctrine.orm.entity_manager' instead of entity manager ...

just found answer here :

use symfony\component\dependencyinjection\reference;  container->getdefinition('alsatian_form.form_event_subscriber.extensible')                 ->addmethodcall('setentitymanager', array(new reference("doctrine.orm.entity_manager"))); 

i hope can someone.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -