我想在我的Bundle的服務配置的標記定義中放置一個類名(用戶已在app/config/config.yml
中配置)。在服務的標記定義中使用config.yml參數
app/config/config.yml
:
my:
class_name: AppBundle\Entity\Product
我的包的配置:services.xml
<service id="my.entity_listener" class="My\EventListener\MyListener">
<tag name="doctrine.orm.entity_listener" entity="%my.class_name%" event="preUpdate" />
</service>
這有可能以任何方式?我所能得到的只是%my.class_name%。它不會在標籤定義中被替換。雖然,我的依賴注入的工作,因爲它取代了它也只是以上,在同一個配置文件:
<service id="my.param_converter" class="My\ParamConverter\MyParamConverter">
<tag name="request.param_converter" converter="user" priority="10" />
<argument type="service" id="doctrine.orm.default_entity_manager" />
<argument>%my.class_name%</argument> <!-- Replaced by AppBundle\Entity\Product -->
</service>
沒有辦法直接使用my.class_name作爲參數,因爲它不是參數。您將需要使用編譯器通行證來修改您的服務定義。可能有點涉及:http://symfony.com/doc/current/bundles/configuration.html和http://symfony.com/doc/current/service_container/compiler_passes.html – Cerad