Skip to content

Commit

Permalink
Update tags.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
ro0NL committed Oct 6, 2017
1 parent 2e5c87f commit ed70659
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions service_container/tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,13 @@ first constructor argument to the ``App\HandlerCollection`` service:
# app/config/services.yml
services:
App\Handler\One:
AppBundle\Handler\One:
tags: [app.handler]
App\Handler\Two:
AppBundle\Handler\Two:
tags: [app.handler]
App\HandlerCollection:
AppBundle\HandlerCollection:
# inject all services tagged with app.handler as first argument
arguments: [!tagged app.handler]
Expand All @@ -446,15 +446,15 @@ first constructor argument to the ``App\HandlerCollection`` service:
http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="App\Handler\One">
<service id="AppBundle\Handler\One">
<tag name="app.handler" />
</service>
<service id="App\Handler\Two">
<service id="AppBundle\Handler\Two">
<tag name="app.handler" />
</service>
<service id="App\HandlerCollection">
<service id="AppBundle\HandlerCollection">
<!-- inject all services tagged with app.handler as first argument -->
<argument type="tagged" tag="app.handler" />
</service>
Expand All @@ -466,13 +466,13 @@ first constructor argument to the ``App\HandlerCollection`` service:
// app/config/services.php
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
$container->register(App\Handler\One::class)
$container->register(AppBundle\Handler\One::class)
->addTag('app.handler');
$container->register(App\Handler\Two::class)
$container->register(AppBundle\Handler\Two::class)
->addTag('app.handler');
$container->register(App\HandlerCollection::class)
$container->register(AppBundle\HandlerCollection::class)
// inject all services tagged with app.handler as first argument
->addArgument(new TaggedIteratorArgument('app.handler'));
Expand All @@ -481,6 +481,9 @@ application handlers.

.. code-block:: php
// src/AppBundle/HandlerCollection.php
namespace AppBundle;
class HandlerCollection
{
public function __construct(iterable $handlers)
Expand All @@ -498,7 +501,7 @@ application handlers.
# app/config/services.yml
services:
App\Handler\One:
AppBundle\Handler\One:
tags:
- { name: app.handler, priority: 20 }
Expand All @@ -512,7 +515,7 @@ application handlers.
http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="App\Handler\One">
<service id="AppBundle\Handler\One">
<tag name="app.handler" priority="20" />
</service>
</services>
Expand All @@ -521,8 +524,7 @@ application handlers.
.. code-block:: php
// app/config/services.php
$container->register(App\Handler\One::class)
$container->register(AppBundle\Handler\One::class)
->addTag('app.handler', array('priority' => 20));
Note that any other custom attributes will be ignored by this feature.

0 comments on commit ed70659

Please sign in to comment.