Skip to content

Commit 97d8f61

Browse files
committed
minor #4403 Improved naming (WouterJ)
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
2 parents 6298595 + 2665e1f commit 97d8f61

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

components/dependency_injection/tags.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ custom tag::
153153
$taggedServices = $container->findTaggedServiceIds(
154154
'acme_mailer.transport'
155155
);
156-
foreach ($taggedServices as $id => $attributes) {
156+
foreach ($taggedServices as $id => $tags) {
157157
$definition->addMethodCall(
158158
'addTransport',
159159
array(new Reference($id))
@@ -178,7 +178,7 @@ run when the container is compiled::
178178
use Symfony\Component\DependencyInjection\ContainerBuilder;
179179

180180
$container = new ContainerBuilder();
181-
$container->addCompilerPass(new TransportCompilerPass);
181+
$container->addCompilerPass(new TransportCompilerPass());
182182

183183
.. note::
184184

@@ -291,8 +291,8 @@ use this, update the compiler::
291291
$taggedServices = $container->findTaggedServiceIds(
292292
'acme_mailer.transport'
293293
);
294-
foreach ($taggedServices as $id => $tagAttributes) {
295-
foreach ($tagAttributes as $attributes) {
294+
foreach ($taggedServices as $id => $tags) {
295+
foreach ($tags as $attributes) {
296296
$definition->addMethodCall(
297297
'addTransport',
298298
array(new Reference($id), $attributes["alias"])
@@ -302,7 +302,7 @@ use this, update the compiler::
302302
}
303303
}
304304

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

0 commit comments

Comments
 (0)