0
我想配置一个服务来自动将一个现有的DI容器注入到它。我ContentQuery
类已经extends
另一个类,所以它必须改为实行ContainerAwareInterface
和使用call
块配置实际注射:如何将Symfony DI容器本身注入到服务中?
<services>
<service id="my_module.model.content_query" class="MyModule\Model\ContentQuery">
<call method="setContainer">
<argument type="service" id="container" />
</call>
</service>
</services>
的问题是,我不知道如何来识别XML容器本身。使用上面的配置,我得到这个错误:
the service "my_module.model.content_query" has a dependency on a non-existent service "container"
我宁愿只是这样做在PHP中,我认为我能想出很容易,但是要使用XML的决定是从我手中的这个时候。那么有没有办法将Container实例识别为服务?
应用程序/控制台调试:容器是你的朋友 – Cerad