Skip to content

Improved naming #4403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2014
Merged
Changes from all commits
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
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) {
Copy link
Member

Choose a reason for hiding this comment

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

hurray for this change. It is time to use the proper naming

$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.