@@ -120,12 +120,15 @@ configuration files, even if they use a different format:
120120 .. code-block :: php
121121
122122 // config/services.php
123- $loader->import('legacy_config.xml');
124- // the third optional argument of import() is 'ignore_errors', which
125- // silently discards errors if the loaded file doesn't exist
126- $loader->import('my_config_file.yaml', null, true);
127- // glob expressions are also supported to load multiple files
128- $loader->import('/etc/myapp/*.yaml');
123+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
124+
125+ return static function (ContainerConfigurator $container) {
126+ $container->import('legacy_config.php');
127+ // ignore_errors (3rd parameter) silently discards errors if the loaded file doesn't exist
128+ $container->import('my_config_file.xml', null, true);
129+ // glob expressions are also supported to load multiple files
130+ $container->import('/etc/myapp/*.yaml');
131+ };
129132
130133 // ...
131134
@@ -209,24 +212,29 @@ reusable configuration value. By convention, parameters are defined under the
209212 .. code-block :: php
210213
211214 // config/services.php
212- // the parameter name is an arbitrary string (the 'app.' prefix is recommended
213- // to better differentiate your parameters from Symfony parameters).
214- $container->setParameter('app.admin_email', 'something@example.com');
215+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
215216
216- // boolean parameters
217- $container->setParameter('app.enable_v2_protocol', true);
217+ use App\Entity\BlogPost;
218218
219- // array/collection parameters
220- $container->setParameter('app.supported_locales', ['en', 'es', 'fr']);
219+ return static function (ContainerConfigurator $container) {
220+ $container->parameters()
221+ // the parameter name is an arbitrary string (the 'app.' prefix is recommended
222+ // to better differentiate your parameters from Symfony parameters).
223+ ->set('app.admin_email', 'something@example.com')
221224
222- // binary content parameters (use the PHP escape sequences)
223- $container->setParameter ('app.some_parameter ', 'This is a Bell char: \x07');
225+ // boolean parameters
226+ ->set ('app.enable_v2_protocol ', true)
224227
225- // PHP constants as parameter values
226- use App\Entity\BlogPost;
228+ // array/collection parameters
229+ ->set('app.supported_locales', ['en', 'es', 'fr'])
227230
228- $container->setParameter('app.some_constant', GLOBAL_CONSTANT);
229- $container->setParameter('app.another_constant', BlogPost::MAX_ITEMS);
231+ // binary content parameters (use the PHP escape sequences)
232+ ->set('app.some_parameter', 'This is a Bell char: \x07')
233+
234+ // PHP constants as parameter values
235+ ->set('app.some_constant', GLOBAL_CONSTANT)
236+ ->set('app.another_constant', BlogPost::MAX_ITEMS);
237+ };
230238
231239 // ...
232240
@@ -278,12 +286,17 @@ configuration file using a special syntax: wrap the parameter name in two ``%``
278286 .. code-block :: php
279287
280288 // config/packages/some_package.php
281- $container->loadFromExtension('some_package', [
282- // any string surrounded by two % is replaced by that parameter value
283- 'email_address' => '%app.admin_email%',
289+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
290+
291+ return static function (ContainerConfigurator $container) {
292+ $container->extension('some_package', [
293+ // any string surrounded by two % is replaced by that parameter value
294+ 'email_address' => '%app.admin_email%',
295+
296+ // ...
297+ ]);
298+ };
284299
285- // ...
286- ]);
287300
288301 .. note ::
289302
@@ -310,7 +323,12 @@ configuration file using a special syntax: wrap the parameter name in two ``%``
310323 .. code-block :: php
311324
312325 // config/services.php
313- $container->setParameter('url_pattern', 'http://symfony.com/?foo=%%s& ; bar=%%d');
326+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
327+
328+ return static function (ContainerConfigurator $container) {
329+ $container->parameters()
330+ ->set('url_pattern', 'http://symfony.com/?foo=%%s& ; bar=%%d');
331+ };
314332
315333 .. include :: /components/dependency_injection/_imports-parameters-note.rst.inc
316334
@@ -478,12 +496,16 @@ This example shows how you could configure the database connection using an env
478496 .. code-block :: php
479497
480498 // config/packages/doctrine.php
481- $container->loadFromExtension('doctrine', [
482- 'dbal' => [
483- // by convention the env var names are always uppercase
484- 'url' => '%env(resolve:DATABASE_URL)%',
485- ]
486- ]);
499+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
500+
501+ return static function (ContainerConfigurator $container) {
502+ $container->extension('doctrine', [
503+ 'dbal' => [
504+ // by convention the env var names are always uppercase
505+ 'url' => '%env(resolve:DATABASE_URL)%',
506+ ]
507+ ]);
508+ };
487509
488510 .. seealso ::
489511
@@ -772,13 +794,18 @@ doesn't work for parameters:
772794 .. code-block :: php
773795
774796 // config/services.php
797+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
798+
775799 use App\Service\MessageGenerator;
776- use Symfony\Component\DependencyInjection\Reference;
777800
778- $container->setParameter('app.contents_dir', '...');
801+ return static function (ContainerConfigurator $container) {
802+ $container->parameters()
803+ ->set('app.contents_dir', '...');
779804
780- $container->getDefinition(MessageGenerator::class)
781- ->setArgument('$contentsDir', '%app.contents_dir%');
805+ $container->services()
806+ ->get(MessageGenerator::class)
807+ ->arg('$contentsDir', '%app.contents_dir%');
808+ };
782809
783810 If you inject the same parameters over and over again, use the
784811``services._defaults.bind `` option instead. The arguments defined in that option are
@@ -824,18 +851,22 @@ whenever a service/controller defines a ``$projectDir`` argument, use this:
824851 .. code-block :: php
825852
826853 // config/services.php
854+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
855+
827856 use App\Controller\LuckyController;
828857 use Psr\Log\LoggerInterface;
829858 use Symfony\Component\DependencyInjection\Reference;
830859
831- $container->register(LuckyController::class)
832- ->setPublic(true)
833- ->setBindings([
834- // pass this value to any $projectDir argument for any service
835- // that's created in this file (including controller arguments)
836- '$projectDir' => '%kernel.project_dir%',
837- ])
838- ;
860+ return static function (ContainerConfigurator $container) {
861+ $container->services()
862+ ->set(LuckyController::class)
863+ ->public()
864+ ->args([
865+ // pass this value to any $projectDir argument for any service
866+ // that's created in this file (including controller arguments)
867+ '$projectDir' => '%kernel.project_dir%',
868+ ]);
869+ };
839870
840871 .. seealso ::
841872
0 commit comments