@@ -106,10 +106,8 @@ configuration files, even if they use a different format:
106
106
<container xmlns =" http://symfony.com/schema/dic/services"
107
107
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
108
108
xsi : schemaLocation =" http://symfony.com/schema/dic/services
109
- https://symfony.com/schema/dic/services/services-1.0.xsd
110
- http://symfony.com/schema/dic/symfony
111
- https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
112
-
109
+ https://symfony.com/schema/dic/services/services-1.0.xsd"
110
+ >
113
111
<imports >
114
112
<import resource =" legacy_config.php" />
115
113
<!-- glob expressions are also supported to load multiple files -->
@@ -140,9 +138,9 @@ configuration files, even if they use a different format:
140
138
$container->import('my_config_file.yaml', null, 'not_found');
141
139
// 'ignore_errors' set to true silently discards all errors (including invalid code and not found)
142
140
$container->import('my_config_file.yaml', null, true);
143
- };
144
141
145
- // ...
142
+ // ...
143
+ };
146
144
147
145
.. versionadded :: 4.4
148
146
@@ -191,12 +189,9 @@ reusable configuration value. By convention, parameters are defined under the
191
189
<?xml version =" 1.0" encoding =" UTF-8" ?>
192
190
<container xmlns =" http://symfony.com/schema/dic/services"
193
191
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
194
- xmlns : framework =" http://symfony.com/schema/dic/symfony"
195
192
xsi : schemaLocation =" http://symfony.com/schema/dic/services
196
- https://symfony.com/schema/dic/services/services-1.0.xsd
197
- http://symfony.com/schema/dic/symfony
198
- https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
199
-
193
+ https://symfony.com/schema/dic/services/services-1.0.xsd"
194
+ >
200
195
<parameters >
201
196
<!-- the parameter name is an arbitrary string (the 'app.' prefix is recommended
202
197
to better differentiate your parameters from Symfony parameters). -->
@@ -249,10 +244,11 @@ reusable configuration value. By convention, parameters are defined under the
249
244
250
245
// PHP constants as parameter values
251
246
->set('app.some_constant', GLOBAL_CONSTANT)
252
- ->set('app.another_constant', BlogPost::MAX_ITEMS);
253
- } ;
247
+ ->set('app.another_constant', BlogPost::MAX_ITEMS)
248
+ ;
254
249
255
- // ...
250
+ // ...
251
+ };
256
252
257
253
.. caution ::
258
254
@@ -287,12 +283,12 @@ configuration file using a special syntax: wrap the parameter name in two ``%``
287
283
<?xml version =" 1.0" encoding =" UTF-8" ?>
288
284
<container xmlns =" http://symfony.com/schema/dic/services"
289
285
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
290
- xmlns : framework = " http ://symfony.com /schema/dic/symfony "
291
- xsi : schemaLocation =" http ://symfony.com/schema/dic/services
286
+ xmlns : some-package = " https ://example.org /schema/dic/some-package "
287
+ xsi : schemaLocation =" https ://symfony.com/schema/dic/services
292
288
https://symfony.com/schema/dic/services/services-1.0.xsd
293
- http ://symfony.com /schema/dic/symfony
294
- https://symfony.com /schema/dic/symfony/symfony- 1.0.xsd" >
295
-
289
+ https ://example.org /schema/dic/some-package
290
+ https://example.org /schema/dic/some-package/some-package- 1.0.xsd"
291
+ >
296
292
<!-- any string surrounded by two % is replaced by that parameter value -->
297
293
<some-package : config email-address =" %app.admin_email%" >
298
294
<!-- ... -->
@@ -313,7 +309,6 @@ configuration file using a special syntax: wrap the parameter name in two ``%``
313
309
]);
314
310
};
315
311
316
-
317
312
.. note ::
318
313
319
314
If some parameter value includes the ``% `` character, you need to escape it
@@ -333,18 +328,17 @@ configuration file using a special syntax: wrap the parameter name in two ``%``
333
328
334
329
<!-- config/services.xml -->
335
330
<parameters >
331
+ <!-- Parsed as 'https://symfony.com/?foo=%s&bar=%d' -->
336
332
<parameter key =" url_pattern" >http://symfony.com/?foo=%%s& bar=%%d</parameter >
337
333
</parameters >
338
334
339
335
.. code-block :: php
340
336
341
337
// config/services.php
342
- namespace Symfony\Component\DependencyInjection\Loader\Configurator;
343
-
344
- return static function (ContainerConfigurator $container) {
345
- $container->parameters()
346
- ->set('url_pattern', 'http://symfony.com/?foo=%%s& ; bar=%%d');
347
- };
338
+ $container->parameters()
339
+ // Parsed as 'https://symfony.com/?foo=%s& ; bar=%d'
340
+ ->set('url_pattern', 'http://symfony.com/?foo=%%s& ; bar=%%d')
341
+ ;
348
342
349
343
.. include :: /components/dependency_injection/_imports-parameters-note.rst.inc
350
344
@@ -508,13 +502,14 @@ This example shows how you could configure the database connection using an env
508
502
xsi : schemaLocation =" http://symfony.com/schema/dic/services
509
503
https://symfony.com/schema/dic/services/services-1.0.xsd
510
504
http://symfony.com/schema/dic/doctrine
511
- https://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd" >
512
-
505
+ https://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd"
506
+ >
513
507
<doctrine : config >
514
508
<!-- by convention the env var names are always uppercase -->
515
509
<doctrine : dbal url =" %env(resolve:DATABASE_URL)%" />
516
510
</doctrine : config >
517
511
512
+ <!-- ... -->
518
513
</container >
519
514
520
515
.. code-block :: php
@@ -528,6 +523,8 @@ This example shows how you could configure the database connection using an env
528
523
// by convention the env var names are always uppercase
529
524
'url' => '%env(resolve:DATABASE_URL)%',
530
525
],
526
+
527
+ // ...
531
528
]);
532
529
};
533
530
@@ -805,6 +802,8 @@ doesn't work for parameters:
805
802
app.contents_dir : ' ...'
806
803
807
804
services :
805
+ # ...
806
+
808
807
App\Service\MessageGenerator :
809
808
arguments :
810
809
$contentsDir : ' %app.contents_dir%'
@@ -816,13 +815,15 @@ doesn't work for parameters:
816
815
<container xmlns =" http://symfony.com/schema/dic/services"
817
816
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
818
817
xsi : schemaLocation =" http://symfony.com/schema/dic/services
819
- https://symfony.com/schema/dic/services/services-1.0.xsd" >
820
-
818
+ https://symfony.com/schema/dic/services/services-1.0.xsd"
819
+ >
821
820
<parameters >
822
821
<parameter key =" app.contents_dir" >...</parameter >
823
822
</parameters >
824
823
825
824
<services >
825
+ <!-- ... -->
826
+
826
827
<service id =" App\Service\MessageGenerator" >
827
828
<argument key =" $contentsDir" >%app.contents_dir%</argument >
828
829
</service >
@@ -838,11 +839,15 @@ doesn't work for parameters:
838
839
839
840
return static function (ContainerConfigurator $container) {
840
841
$container->parameters()
841
- ->set('app.contents_dir', '...');
842
+ ->set('app.contents_dir', '...')
843
+ ;
842
844
843
845
$container->services()
846
+ // ...
847
+
844
848
->get(MessageGenerator::class)
845
- ->arg('$contentsDir', '%app.contents_dir%');
849
+ ->arg('$contentsDir', '%app.contents_dir%')
850
+ ;
846
851
};
847
852
848
853
If you inject the same parameters over and over again, use the
@@ -873,8 +878,8 @@ whenever a service/controller defines a ``$projectDir`` argument, use this:
873
878
<container xmlns =" http://symfony.com/schema/dic/services"
874
879
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
875
880
xsi : schemaLocation =" http://symfony.com/schema/dic/services
876
- https://symfony.com/schema/dic/services/services-1.0.xsd" >
877
-
881
+ https://symfony.com/schema/dic/services/services-1.0.xsd"
882
+ >
878
883
<services >
879
884
<defaults autowire =" true" autoconfigure =" true" public =" false" >
880
885
<!-- pass this value to any $projectDir argument for any service
@@ -891,16 +896,15 @@ whenever a service/controller defines a ``$projectDir`` argument, use this:
891
896
// config/services.php
892
897
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
893
898
894
<
8A3F
/code>
- use App\Controller\LuckyController;
895
-
896
899
return static function (ContainerConfigurator $container) {
897
900
$container->services()
898
901
->defaults()
899
902
// pass this value to any $projectDir argument for any service
900
903
// that's created in this file (including controller arguments)
901
- ->bind('$projectDir', '%kernel.project_dir%');
904
+ ->bind('$projectDir', '%kernel.project_dir%')
902
905
903
- // ...
906
+ // ...
907
+ ;
904
908
};
905
909
906
910
.. seealso ::
0 commit comments