ppokatilo/magic-injection-bundle
最新稳定版本:v1.0.3
Composer 安装命令:
composer require ppokatilo/magic-injection-bundle
包简介
Magically inject dependencies into services
README 文档
README
This Symfony2 bundle provides a way to magically inject dependencies into your services. The dependencies will not be available in the constructor. To use it, you need to complete the following steps:
- Add the tag
magic_injection.injectable_serviceto the service you wish to inject. The tag takes an optional argument calledtype, which you can use to group injectable services. - Add the tag
magic_injection.injection_targetto the service which should receive the injected services. - Finally, annotate properties with the
MagicInjectionannotation, which will take an optionaltypeargument that refers to a group of injectable services.
Example usage
- services.yml
services: service.that.will.be.injected: class: Service\MyServiceA tags: - { name: magic_injection.injectable_service, type: my_services } service.that.has.a.dependency: class: Service\MyServiceB tags: - { name: magic_injection.injection_target }
- MyServiceB.php
class MyServiceB { /** * @MagicInjection(type="my_services") * @var \Service\MyServiceA */ private $myServiceA; public function __construct() { assert($this->myServiceA === null); } public function foo() { $this->myServiceA->bar(); } }
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-15