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