0

有没有办法将捆绑包注入服务?

我想像这样编写我的服务构造函数:

<?php
use Symfony\Component\HttpKernel\Bundle\Bundle;

class MyService
{
    /** @var Bundle */
    private $bundle;

    public function __construct(Bundle $bundle) 
    {
        $this->bundle = $bundle;
    }
}

对于services.yml我想要这样的东西:

services:
    my_service:
        class:     MyService
        arguments: ['how_can_i_reference_a_bundle']
4

1 回答 1

7

您的捆绑包可以设置为这样的服务:

services:
    acme_foo_bundle:
        class: Acme\Foo\AcmeFooBundle
        factory_service: kernel
        factory_method: getBundle
        arguments:
            - "AcmeFooBundle"
于 2012-09-27T08:43:39.607 回答