Skip to content

Commit

Permalink
minor #4403 Improved naming (WouterJ)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.3 branch.

Discussion
----------

Improved naming

| Q   | A
| --- | ---
| Doc fix? | yes
| New docs? | no
| Applies to | all
| Fixed tickets | -

I always found this very confusing. Today, I decided to try to tackle it. It's hard to explain correctly using not that many words. I would like to hear other suggestions if you think those are better :)

Commits
-------

2665e1f Improved naming
  • Loading branch information
wouterj committed Nov 18, 2014
2 parents 6298595 + 2665e1f commit 97d8f61
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions components/dependency_injection/tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ custom tag::
$taggedServices = $container->findTaggedServiceIds(
'acme_mailer.transport'
);
foreach ($taggedServices as $id => $attributes) {
foreach ($taggedServices as $id => $tags) {
$definition->addMethodCall(
'addTransport',
array(new Reference($id))
Expand All @@ -178,7 +178,7 @@ run when the container is compiled::
use Symfony\Component\DependencyInjection\ContainerBuilder;

$container = new ContainerBuilder();
$container->addCompilerPass(new TransportCompilerPass);
$container->addCompilerPass(new TransportCompilerPass());

.. note::

Expand Down Expand Up @@ -291,8 +291,8 @@ use this, update the compiler::
$taggedServices = $container->findTaggedServiceIds(
'acme_mailer.transport'
);
foreach ($taggedServices as $id => $tagAttributes) {
foreach ($tagAttributes as $attributes) {
foreach ($taggedServices as $id => $tags) {
foreach ($tags as $attributes) {
$definition->addMethodCall(
'addTransport',
array(new Reference($id), $attributes["alias"])
Expand All @@ -302,7 +302,7 @@ use this, update the compiler::
}
}

The trickiest part is the ``$attributes`` variable. Because you can use the
same tag many times on the same service (e.g. you could theoretically tag
the same service 5 times with the ``acme_mailer.transport`` tag), ``$attributes``
is an array of the tag information for each tag on that service.
The double loop may be confusing. This is because a service can have more than one
tag. You tag a service twice or more with the ``acme_mailer.transport`` tag. The
second foreach loop iterates over the ``acme_mailer.transport`` tags set for the
current service and gives you the attributes.

0 comments on commit 97d8f61

Please sign in to comment.