Symfony依赖项注入XML到YAML
如何在YAML模式中定义这样的服务 XML: 编辑:完整(长)yaml定义。 如何定义类似的XML,如: 为您效劳Symfony依赖项注入XML到YAML,symfony,Symfony,如何在YAML模式中定义这样的服务 XML: 编辑:完整(长)yaml定义。 如何定义类似的XML,如: 为您效劳 services: my_service_factory: class: OtherFactoryServiceClass my_service: class: MyClass factory_service: my_service_factory factory_method: get arguments: [other_s
services:
my_service_factory:
class: OtherFactoryServiceClass
my_service:
class: MyClass
factory_service: my_service_factory
factory_method: get
arguments: [other_service_param] # arguments are injected in "OtherFactoryServiceClass::get"
@ツ利弗布尔提供更多信息。“预期的PHP:(在容器转储中)”不够清楚。我们可以合并成一个定义吗?据我所知,不可能。因为在yaml中很难区分子服务定义和数组。
protected function getMYServiceService()
{
return $this->services['my_service'] = new \MyClass($this->get('other_facoty_service')->get('other_service_param'));
}
services:
an_other_service:
public: false
class: OtherFacotryServiceClass
factory_service: other_facoty_service
factory_method: get
arguments: [other_service_param]
my_service:
class: MyClass
arguments: [@an_other_service]
services:
# THIS'S WRONG FORMAT!!
my_service:
class: MyClass
arguments:
-
class: OtherFacotryServiceClass
factory_service: other_facoty_service
factory_method: get
arguments: [other_service_param]
services:
my_service_factory:
class: OtherFactoryServiceClass
my_service:
class: MyClass
factory_service: my_service_factory
factory_method: get
arguments: [other_service_param] # arguments are injected in "OtherFactoryServiceClass::get"