@@ -45,8 +45,8 @@ You can register this in the container as a service::
4545
4646 use Symfony\Component\DependencyInjection\ContainerBuilder;
4747
48- $containerBuilder = new ContainerBuilder();
49- $containerBuilder ->register('mailer', 'Mailer');
48+ $container = new ContainerBuilder();
49+ $container ->register('mailer', 'Mailer');
5050
5151An improvement to the class to make it more flexible would be to allow
5252the container to set the ``transport `` used. If you change the class
@@ -66,8 +66,8 @@ Then you can set the choice of transport in the container::
6666
6767 use Symfony\Component\DependencyInjection\ContainerBuilder;
6868
69- $containerBuilder = new ContainerBuilder();
70- $containerBuilder
69+ $container = new ContainerBuilder();
70+ $container
7171 ->register('mailer', 'Mailer')
7272 ->addArgument('sendmail');
7373
@@ -81,9 +81,9 @@ the ``Mailer`` service's constructor argument::
8181
8282 use Symfony\Component\DependencyInjection\ContainerBuilder;
8383
84- $containerBuilder = new ContainerBuilder();
85- $containerBuilder ->setParameter('mailer.transport', 'sendmail');
86- $containerBuilder
84+ $container = new ContainerBuilder();
85+ $container ->setParameter('mailer.transport', 'sendmail');
86+ $container
8787 ->register('mailer', 'Mailer')
8888 ->addArgument('%mailer.transport%');
8989
@@ -108,14 +108,14 @@ not exist yet. Use the ``Reference`` class to tell the container to inject the
108108 use Symfony\Component\DependencyInjection\ContainerBuilder;
109109 use Symfony\Component\DependencyInjection\Reference;
110110
111- $containerBuilder = new ContainerBuilder();
111+ $container = new ContainerBuilder();
112112
113- $containerBuilder ->setParameter('mailer.transport', 'sendmail');
114- $containerBuilder
113+ $container ->setParameter('mailer.transport', 'sendmail');
114+ $container
115115 ->register('mailer', 'Mailer')
116116 ->addArgument('%mailer.transport%');
117117
118- $containerBuilder
118+ $container
119119 ->register('newsletter_manager', 'NewsletterManager')
120120 ->addArgument(new Reference('mailer'));
121121
@@ -140,14 +140,14 @@ If you do want to though then the container can call the setter method::
140140 use Symfony\Component\DependencyInjection\ContainerBuilder;
141141 use Symfony\Component\DependencyInjection\Reference;
142142
143- $containerBuilder = new ContainerBuilder();
143+ $container = new ContainerBuilder();
144144
145- $containerBuilder ->setParameter('mailer.transport', 'sendmail');
146- $containerBuilder
145+ $container ->setParameter('mailer.transport', 'sendmail');
146+ $container
147147 ->register('mailer', 'Mailer')
148148 ->addArgument('%mailer.transport%');
149149
150- $containerBuilder
150+ $container
151151 ->register('newsletter_manager', 'NewsletterManager')
152152 ->addMethodCall('setMailer', [new Reference('mailer')]);
153153
@@ -156,11 +156,11 @@ like this::
156156
157157 use Symfony\Component\DependencyInjection\ContainerBuilder;
158158
159- $containerBuilder = new ContainerBuilder();
159+ $container = new ContainerBuilder();
160160
161161 // ...
162162
163- $newsletterManager = $containerBuilder ->get('newsletter_manager');
163+ $newsletterManager = $container ->get('newsletter_manager');
164164
165165Getting Services That Don't Exist
166166~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -224,8 +224,8 @@ Loading an XML config file::
224224 use Symfony\Component\DependencyInjection\ContainerBuilder;
225225 use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
226226
227- $containerBuilder = new ContainerBuilder();
228- $loader = new XmlFileLoader($containerBuilder , new FileLocator(__DIR__));
227+ $container = new ContainerBuilder();
228+ $loader = new XmlFileLoader($container , new FileLocator(__DIR__));
229229 $loader->load('services.xml');
230230
231231Loading a YAML config file::
@@ -234,8 +234,8 @@ Loading a YAML config file::
234234 use Symfony\Component\DependencyInjection\ContainerBuilder;
235235 use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
236236
237- $containerBuilder = new ContainerBuilder();
238- $loader = new YamlFileLoader($containerBuilder , new FileLocator(__DIR__));
237+ $container = new ContainerBuilder();
238+ $loader = new YamlFileLoader($container , new FileLocator(__DIR__));
239239 $loader->load('services.yaml');
240240
241241.. note ::
@@ -259,8 +259,8 @@ into a separate config file and load it in a similar way::
259259 use Symfony\Component\DependencyInjection\ContainerBuilder;
260260 use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
261261
262- $containerBuilder = new ContainerBuilder();
263- $loader = new PhpFileLoader($containerBuilder , new FileLocator(__DIR__));
262+ $container = new ContainerBuilder();
263+ $loader = new PhpFileLoader($container , new FileLocator(__DIR__));
264264 $loader->load('services.php');
265265
266266You can now set up the ``newsletter_manager `` and ``mailer `` services using
@@ -313,13 +313,13 @@ config files:
313313
314314 namespace Symfony\Component\DependencyInjection\Loader\Configurator;
315315
316- return static function (ContainerConfigurator $containerConfigurator ) {
317- $containerConfigurator ->parameters()
316+ return static function (ContainerConfigurator $container ) {
317+ $container ->parameters()
318318 // ...
319319 ->set('mailer.transport', 'sendmail')
320320 ;
321321
322- $services = $containerConfigurator ->services();
322+ $services = $container ->services();
323323 $services->set('mailer', 'Mailer')
324324 ->args(['%mailer.transport%'])
325325 ;
0 commit comments