dwo / tagged_services
此包已被 废弃 且不再维护。没有建议的替代包。
通过服务配置查找标记服务
v1.0.0
2015-04-08 11:01 UTC
Requires
- php: >=5.3.0
- pimple/pimple: ~3.0
- symfony/dependency-injection: >=2.3@stable
Requires (Dev)
- phpunit/phpunit: ~3.7.0
This package is not auto-updated.
Last update: 2023-04-01 09:57:39 UTC
README
============== TaggedServices
通过服务配置查找和使用您的标记服务,而不是每次都构建编译器遍历。
安装
=================
将 CompilerPass 添加到您的 AppKernel 或一个 Bundle 中。
#AppKernel.php protected function buildContainer() { $container = parent::buildContainer(); $container->addCompilerPass(new TaggedServicesPass()); }
或者到您的 Bundle 中
#FooBundle.php protected function build(ContainerBuilder $container) { parent::build($container); $container->addCompilerPass(new TaggedServicesPass()); }
标记服务
=====================
按照常规用您自己的标记标记服务,并使用 'type' 参数给它们命名。
#services.yml services: my.service.foo: class: My\Service\Foo tags: - {name: "my.services", type: "foo"} my.service.bar: class: My\Service\Bar tags: - {name: "my.services", type: "bar"}
使用标记服务
============================
现在将 'tagged_services' 标记与 'find_tag' 参数添加到注入所有标记服务的服务中。
#services.yml services: my.service.container: class: My\Service\MyServiceContainer arguments: [[]] tags: - { name: 'tagged_services', find_tag: 'my.services' }
现在,您的 MyServiceContainer 将获得一个包含所有标记服务的数组。
#MyServiceContainer.php class MyServiceContainer { private $myServices = array(); private $myFooService; function __construct(array $myServices) { $this->myServices = $myServices; $this->myFooService = $myServices['foo']; } }