Skip to content

Commit 74b0a16

Browse files
committed
[components] Tweaks for #1398 - cleaning up some language
1 parent c8ca957 commit 74b0a16

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

components/dependency_injection/tags.rst

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
How to make your Services use Tags
55
==================================
66

7-
You can ask a container builder for any services that were tagged when registered
8-
with it. This is useful in compiler passes where you can find services which
9-
were registered in config files you do not have control over and make use
10-
of them. This is useful if your service handles a collection of some kind,
11-
or implements a "chain", in which several alternative strategies are tried
12-
until one of them is successful. You can then allow services to be registered
13-
with a tag and add these services to your collection or chain.
14-
15-
For example, if you are using Swift Mailer and want to implement a
16-
of a "transport chain", which is a collection of classes implementing ``\Swift_Transport``.
17-
Using the chain, Swift Mailer can try several ways of transport, until one
18-
succeeds.
7+
Tags are a generic string (along with some options) that can be applied to
8+
any service. By themselves, tags don't actually the functionality of your
9+
services in any way. But if you choose to, you can ask a container builder
10+
for a list of all services that were tagged with some specific tag. This
11+
is useful in compiler passes where you can find these services and use or
12+
modify them in some specific way.
13+
14+
For example, if you are using Swift Mailer you might imagine that you want
15+
to implement a "transport chain", which is a collection of classes implementing
16+
``\Swift_Transport``. Using the chain, you'll want Swift Mailer to try several
17+
ways of transporting the message until one succeeds.
1918

2019
To begin with, define the ``TransportChain`` class::
2120

@@ -111,12 +110,14 @@ As an example we add the following transports as services:
111110
$definitionSendmail->addTag('acme_mailer.transport');
112111
$container->setDefinition('acme_mailer.transport.sendmail', $definitionSendmail);
113112
114-
Notice the tags named "acme_mailer.transport". This is the custom tag to use ion your compiler pass::
113+
Notice that each was given a tag named ``acme_mailer.transport``. This is
114+
the custom tag that you'll use in your compiler pass. The compiler pass
115+
is what makes this tag "mean" something.
115116

116117
Create a ``CompilerPass``
117118
-------------------------
118119

119-
Your compiler pass can then ask the container for any services with the
120+
Your compiler pass can now ask the container for any services with the
120121
custom tag::
121122

122123
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -146,7 +147,7 @@ to the definition of the ``acme_mailer.transport_chain`` service a call to
146147
The first argument of each of these calls will be the mailer transport service
147148
itself.
148149

149-
Register the pass with the container
150+
Register the Pass with the Container
150151
------------------------------------
151152

152153
You also need to register the pass with the container, it will then be

0 commit comments

Comments
 (0)