@@ -208,6 +208,7 @@ subsystem isn't able to find itself the interface implementation to register:
208208
209209 <services >
210210 <service id =" rot13_transformer" class =" Acme\Rot13Transformer" />
211+
211212 <service id =" twitter_client" class =" Acme\TwitterClient" autowire =" true" />
212213 </services >
213214 </container >
@@ -217,12 +218,11 @@ subsystem isn't able to find itself the interface implementation to register:
217218 use Symfony\Component\DependencyInjection\Definition;
218219
219220 // ...
220- $definition1 = new Definition('Acme\Rot13Transformer');
221- $container->setDefinition('rot13_transformer', $definition1);
221+ $container->register('rot13_transformer', 'Acme\Rot13Transformer');
222222
223- $definition2 = new Definition('Acme\TwitterClient');
224- $definition2 ->setAutowired(true);
225- $container->setDefinition('twitter_client', $definition2 );
223+ $clientDefinition = new Definition('Acme\TwitterClient');
224+ $clientDefinition ->setAutowired(true);
225+ $container->setDefinition('twitter_client', $clientDefinition );
226226
227227 The autowiring subsystem detects that the ``rot13_transformer `` service implements
228228the ``TransformerInterface `` and injects it automatically. Even when using
@@ -238,7 +238,7 @@ returning the result of the ROT13 transformation uppercased::
238238
239239 namespace Acme;
240240
241- class UppercaseRot13Transformer implements TransformerInterface
241+ class UppercaseTransformer implements TransformerInterface
242242 {
243243 private $transformer;
244244
@@ -255,7 +255,7 @@ returning the result of the ROT13 transformation uppercased::
255255
256256This class is intended to decorate any transformer and return its value uppercased.
257257
258- We can now refactor the controller to add another endpoint leveraging this new
258+ The controller can now be refactored to add a new endpoint using this uppercase
259259transformer::
260260
261261 namespace Acme\Controller;
@@ -319,13 +319,13 @@ and a Twitter client using it:
319319 class : Acme\TwitterClient
320320 autowire : true
321321
322- uppercase_rot13_transformer :
323- class : Acme\UppercaseRot13Transformer
322+ uppercase_transformer :
323+ class : Acme\UppercaseTransformer
324324 autowire : true
325325
326326 uppercase_twitter_client :
327327 class : Acme\TwitterClient
328- arguments : ['@uppercase_rot13_transformer ']
328+ arguments : ['@uppercase_transformer ']
329329
330330 .. code-block :: xml
331331
@@ -338,10 +338,15 @@ and a Twitter client using it:
338338 <service id =" rot13_transformer" class =" Acme\Rot13Transformer" >
339339 <autowiring-type >Acme\TransformerInterface</autowiring-type >
340340 </service >
341+
341342 <service id =" twitter_client" class =" Acme\TwitterClient" autowire =" true" />
342- <service id =" uppercase_rot13_transformer" class =" Acme\UppercaseRot13Transformer" autowire =" true" />
343+
344+ <service id =" uppercase_transformer" class =" Acme\UppercaseTransformer"
345+ autowire =" true"
346+ />
347+
343348 <service id =" uppercase_twitter_client" class =" Acme\TwitterClient" >
344- <argument type =" service" id =" uppercase_rot13_transformer " />
349+ <argument type =" service" id =" uppercase_transformer " />
345350 </service >
346351 </services >
347352 </container >
@@ -352,21 +357,22 @@ and a Twitter client using it:
352357 use Symfony\Component\DependencyInjection\Definition;
353358
354359 // ...
355- $definition1 = new Definition('Acme\Rot13Transformer');
356- $definition1 ->setAutowiringTypes(array('Acme\TransformerInterface'));
357- $container->setDefinition('rot13_transformer', $definition1 );
360+ $rot13Definition = new Definition('Acme\Rot13Transformer');
361+ $rot13Definition ->setAutowiringTypes(array('Acme\TransformerInterface'));
362+ $container->setDefinition('rot13_transformer', $rot13Definition );
358363
359- $definition2 = new Definition('Acme\TwitterClient');
360- $definition2 ->setAutowired(true);
361- $container->setDefinition('twitter_client', $definition2 );
364+ $clientDefinition = new Definition('Acme\TwitterClient');
365+ $clientDefinition ->setAutowired(true);
366+ $container->setDefinition('twitter_client', $clientDefinition );
362367
363- $definition3 = new Definition('Acme\UppercaseRot13Transformer ');
364- $definition3 ->setAutowired(true);
365- $container->setDefinition('uppercase_rot13_transformer ', $definition3 );
368+ $uppercaseDefinition = new Definition('Acme\UppercaseTransformer ');
369+ $uppercaseDefinition ->setAutowired(true);
370+ $container->setDefinition('uppercase_transformer ', $uppercaseDefinition );
366371
367- $definition4 = new Definition('Acme\TwitterClient');
368- $definition4->addArgument(new Reference('uppercase_rot13_transformer'));
369- $container->setDefinition('uppercase_twitter_client', $definition4);
372+ $uppercaseClientDefinition = new Definition('Acme\TwitterClient', array(
373+ new Reference('uppercase_transformer'),
374+ ));
375+ $container->setDefinition('uppercase_twitter_client', $uppercaseClientDefinition);
370376
371377 This deserves some explanations. You now have two services implementing the
372378``TransformerInterface ``. The autowiring subsystem cannot guess which one
@@ -381,9 +387,9 @@ Fortunately, the ``autowiring_types`` key is here to specify which implementatio
381387to use by default. This key can take a list of types if necessary.
382388
383389Thanks to this setting, the ``rot13_transformer `` service is automatically injected
384- as an argument of the ``uppercase_rot13_transformer `` and ``twitter_client `` services. For
385- the ``uppercase_twitter_client ``, we use a standard service definition to inject
386- the specific ``uppercase_rot13_transformer `` service.
390+ as an argument of the ``uppercase_transformer `` and ``twitter_client `` services. For
391+ the ``uppercase_twitter_client ``, a standard service definition is used to
392+ inject the specific ``uppercase_transformer `` service.
387393
388394As for other RAD features such as the FrameworkBundle controller or annotations,
389395keep in mind to not use autowiring in public bundles nor in large projects with
0 commit comments