Symfony 2在service.xml中传递数组

Nar*_*rek 5 xml arrays connection service symfony

我在services.xml中有服务

<service id="my.connection" class="Doctrine\Bundle\DoctrineBundle\ConnectionFactory">
</service>

<service id="my.main" class="%my.main.class%">
    <call method="foo">
        <argument type="service" id="tmcyc.connection" />
    </call>
</service>
Run Code Online (Sandbox Code Playgroud)

但得到错误:

可捕获的致命错误:传递给Doctrine\Bundle\DoctrineBundle\ConnectionFactory :: __ construct()的参数1必须是一个数组,没有给出...

如何通过参数传递数组?例如:

<service id="my.connection" class="Doctrine\Bundle\DoctrineBundle\ConnectionFactory">
    <argument>[ARRAY]</argument>
</service>
Run Code Online (Sandbox Code Playgroud)

或者我做错了什么?因为这段代码很有用:

$connectionFactory = $this->getContainer()->get('doctrine.dbal.connection_factory');
$conn = $this->createConnection($this->conn);
$conn->executeQuery('SET NAMES utf8');
Run Code Online (Sandbox Code Playgroud)

Мак*_*тов 16

这个例子应该澄清原则:

*.yml

some_id: 
    class: %some.class%
    arguments: 
        - %some.argument%, 
        - [tags: [environment: %kernel.environment%, debug:%kernel.debug%]]
Run Code Online (Sandbox Code Playgroud)

*.xml中

<service id="some_id" class="%some.class%">
    <argument>%some.argument%</argument>
    <argument type="collection">
        <argument key="tags" type="collection">
            <argument key="environment">%kernel.environment%</argument>
            <argument key="debug">%kernel.debug%</argument>
        </argument>
    </argument>
</service>
Run Code Online (Sandbox Code Playgroud)