有没有办法将捆绑注入服务?
我想写这样的服务构造函数:
<?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']
答案 0 :(得分:7)
您的捆绑包可以设置为以下服务:
services:
acme_foo_bundle:
class: Acme\Foo\AcmeFooBundle
factory_service: kernel
factory_method: getBundle
arguments:
- "AcmeFooBundle"