我试图对学说orm做出某种可选的依赖。 根据配置,我想要" doctrine.orm.entity_manager"将setter注入注入alsatian_form.form_event_subscriber.extensible服务。
<?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 I tried with the same syntax as in YAML configuration files.
}
}
}
我认为这肯定是一个语法问题,因为我收到字符串&#39; @ doctrine.orm.entity_manager&#39;而不是实体经理...
答案 0 :(得分:0)
刚刚找到答案here:
use Symfony\Component\DependencyInjection\Reference;
container->getDefinition('alsatian_form.form_event_subscriber.extensible')
->addMethodCall('setEntityManager', array(new Reference("doctrine.orm.entity_manager")));
我希望它可以帮助别人。