merged branch beberlei/TaggedServices (PR #7909)

This PR was submitted for the master branch but it was merged into the 2.1 branch instead (closes #7909).

Discussion
----------

[DependencyInjection] Fix method use + example in doc block

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Fixes using a wrong method in ``findTaggedServiceIds`` and adds an example for the usage and showing the returned data structure as ``@return array`` is not very helpful, the datastructure being a bit unintuitive.

Commits
-------

ad2c955 [DependencyInjection] Fix wrong method in findTaggedServiceIds(), add example to docblock.
This commit is contained in:
Fabien Potencier 2013-05-03 07:08:13 +02:00
commit 3f5cffec8a

View File

@ -848,9 +848,20 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Returns service ids for a given tag.
*
* Example:
*
* $container->register('foo')->addTag('my.tag', array('hello' => 'world'));
*
* $serviceIds = $container->findTaggedServiceIds('my.tag');
* foreach ($serviceIds as $serviceId => $tags) {
* foreach ($tags as $tag) {
* echo $tag['hello'];
* }
* }
*
* @param string $name The tag name
*
* @return array An array of tags
* @return array An array of tags with the tagged service as key, holding a list of attribute arrays.
*
* @api
*/
@ -858,7 +869,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
{
$tags = array();
foreach ($this->getDefinitions() as $id => $definition) {
if ($definition->getTag($name)) {
if ($definition->hasTag($name)) {
$tags[$id] = $definition->getTag($name);
}
}