小编Sob*_*dov的帖子

Symfony2服务容器:使用XML将服务数组参数作为参数注入另一个服务

我有一个参数,应该代表我的services.xml文件中的服务数组:

<parameters>
    <parameter key="decorators.all" type="collection">
        <parameter type="service" id="decorator1" />
        <parameter type="service" id="decorator2" />
        <parameter type="service" id="decorator3" />
    </parameter>
</parameters>

<services>
    <service id="decorator1" class="\FirstDecorator" />
    <service id="decorator2" class="\SecondDecorator" />
    <service id="decorator3" class="\ThirdDecorator" />
</services>
Run Code Online (Sandbox Code Playgroud)

现在我想将此集合作为一组服务注入另一个服务:

<services>
    <service id="notifications_decorator" class="\NotificationsDecorator">
        <argument>%decorators.all%</argument>
    </service>
</services>
Run Code Online (Sandbox Code Playgroud)

但它不起作用.无法理解为什么.我错过了什么?

symfony

4
推荐指数
1
解决办法
4858
查看次数

标签 统计

symfony ×1