@@ -67,7 +67,7 @@ Then you can set the choice of transport in the container::
67
67
$container = new ContainerBuilder();
68
68
$container
69
69
->register('mailer', 'Mailer')
70
- ->addArgument('sendmail');
70
+ ->addArgument('sendmail');
71
71
72
72
This class is now much more flexible as you have separated the choice of
73
73
transport out of the implementation and into the container.
@@ -83,7 +83,7 @@ it a parameter in the container and then referring to this parameter for the
83
83
$container->setParameter('mailer.transport', 'sendmail');
84
84
$container
85
85
->register('mailer', 'Mailer')
86
- ->addArgument('%mailer.transport%');
86
+ ->addArgument('%mailer.transport%');
87
87
88
88
Now that the ``mailer `` service is in the container you can inject it as
89
89
a dependency of other classes. If you have a ``NewsletterManager `` class
@@ -111,11 +111,11 @@ Then you can register this as a service as well and pass the ``mailer`` service
111
111
$container->setParameter('mailer.transport', 'sendmail');
112
112
$container
113
113
->register('mailer', 'Mailer')
114
- ->addArgument('%mailer.transport%');
114
+ ->addArgument('%mailer.transport%');
115
115
116
116
$container
117
117
->register('newsletter_manager', 'NewsletterManager')
118
- ->addArgument(new Reference('mailer'));
118
+ ->addArgument(new Reference('mailer'));
119
119
120
120
If the ``NewsletterManager `` did not require the ``Mailer `` and injecting
121
121
it was only optional then you could use setter injection instead::
@@ -143,11 +143,11 @@ If you do want to though then the container can call the setter method::
143
143
$container->setParameter('mailer.transport', 'sendmail');
144
144
$container
145
145
->register('mailer', 'Mailer')
146
- ->addArgument('%mailer.transport%');
146
+ ->addArgument('%mailer.transport%');
147
147
148
148
$container
149
149
->register('newsletter_manager', 'NewsletterManager')
150
- ->addMethodCall('setMailer', new Reference('mailer'));
150
+ ->addMethodCall('setMailer', new Reference('mailer'));
151
151
152
152
You could then get your ``newsletter_manager `` service from the container
153
153
like this::
@@ -261,4 +261,4 @@ The ``newsletter_manager`` and ``mailer`` services can be set up using config fi
261
261
->register('newsletter_manager', 'NewsletterManager')
262
262
->addMethodCall('setMailer', new Reference('mailer'));
263
263
264
- .. _Packagist : https://packagist.org/packages/symfony/dependency-injection
264
+ .. _Packagist : https://packagist.org/packages/symfony/dependency-injection
0 commit comments