@@ -162,7 +162,7 @@ Adding additional attributes on Tags
162
162
------------------------------------
163
163
164
164
Sometimes you need additional information about each service that's tagged with your tag.
165
- For example, add an alias to our TransportChain
165
+ For example, you might want to add an alias to each TransportChain.
166
166
167
167
To begin with, change the ``TransportChain `` class::
168
168
@@ -175,7 +175,7 @@ To begin with, change the ``TransportChain`` class::
175
175
$this->transports = array();
176
176
}
177
177
178
- public function addTransport(\Swift_Transport $transport, $alias)
178
+ public function addTransport(\Swift_Transport $transport, $alias)
179
179
{
180
180
$this->transports[$alias] = $transport;
181
181
}
@@ -190,9 +190,12 @@ To begin with, change the ``TransportChain`` class::
190
190
}
191
191
}
192
192
}
193
-
194
193
195
- Change the service delaration:
194
+ As you can see, when ``addTransport `` is called, it takes not only a ``Swift_Transport ``
195
+ object, but also a string alias for that transport. So, how can we allow
196
+ each tagged transport service to also supply an alias?
197
+
198
+ To answer this, change the service declaration:
196
199
197
200
.. configuration-block ::
198
201
@@ -222,8 +225,8 @@ Change the service delaration:
222
225
<tag name =" acme_mailer.transport" alias =" bar" />
223
226
</service >
224
227
225
-
226
- The last step is to update the compiler to take care of your additional information ::
228
+ Notice that you've added a generic `` alias `` key to the tag. To actually
229
+ use this, update the compiler::
227
230
228
231
use Symfony\Component\DependencyInjection\ContainerBuilder;
229
232
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
@@ -246,6 +249,8 @@ The last step is to update the compiler to take care of your additional informat
246
249
}
247
250
}
248
251
}
249
-
250
- Take care of ``$attributes `` variable. Because you can use the same tag many times on the same service,
251
- ``$attributes `` is an array of attributes for each tag that refers to the same service.
252
+
253
+ The trickiest part is the ``$attributes `` variable. Because you can use the
254
+ same tag many times on the same service (e.g. you could theoretically tag
255
+ the same service 5 times with the ``acme_mailer.transport `` tag), ``$attributes ``
256
+ is an array of the tag information for each tag on that service.
0 commit comments