Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update tags.rst
  • Loading branch information
ro0NL authored Oct 6, 2017
commit ed70659207f4cf7181e47ad6d31d7efa798afcba
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing filename comment (same for the other formats):

# app/config/services.yml

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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put a comment here describing that this is passing all services tagged with app.handler as an array argument to this class. (Same for the other formats)


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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing namespace and filename comment

{
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 }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be removed (versionadded is a really strange directive). And let's move this to just below the section title

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.