8000 Ensure config blocks are consistent #2 · HeahDude/symfony-docs@e814eea · GitHub
[go: up one dir, main page]

Skip to content

Commit e814eea

Browse files
committed
Ensure config blocks are consistent symfony#2
1 parent da75ee2 commit e814eea

File tree

7 files changed

+467
-299
lines changed

7 files changed

+467
-299
lines changed

configuration.rst

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ configuration files, even if they use a different format:
106106
<container xmlns="http://symfony.com/schema/dic/services"
107107
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
108108
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+
>
113111
<imports>
114112
<import resource="legacy_config.php"/>
115113
<!-- glob expressions are also supported to load multiple files -->
@@ -140,9 +138,9 @@ configuration files, even if they use a different format:
140138
$container->import('my_config_file.yaml', null, 'not_found');
141139
// 'ignore_errors' set to true silently discards all errors (including invalid code and not found)
142140
$container->import('my_config_file.yaml', null, true);
143-
};
144141
145-
// ...
142+
// ...
143+
};
146144
147145
.. versionadded:: 4.4
148146

@@ -191,12 +189,9 @@ reusable configuration value. By convention, parameters are defined under the
191189
<?xml version="1.0" encoding="UTF-8" ?>
192190
<container xmlns="http://symfony.com/schema/dic/services"
193191
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
194-
xmlns:framework="http://symfony.com/schema/dic/symfony"
195192
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+
>
200195
<parameters>
201196
<!-- the parameter name is an arbitrary string (the 'app.' prefix is recommended
202197
to better differentiate your parameters from Symfony parameters). -->
@@ -249,10 +244,11 @@ reusable configuration value. By convention, parameters are defined under the
249244
250245
// PHP constants as parameter values
251246
->set('app.some_constant', GLOBAL_CONSTANT)
252-
->set('app.another_constant', BlogPost::MAX_ITEMS);
253-
};
247+
->set('app.another_constant', BlogPost::MAX_ITEMS)
248+
;
254249
255-
// ...
250+
// ...
251+
};
256252
257253
.. caution::
258254

@@ -287,12 +283,12 @@ configuration file using a special syntax: wrap the parameter name in two ``%``
287283
<?xml version="1.0" encoding="UTF-8" ?>
288284
<container xmlns="http://symfony.com/schema/dic/services"
289285
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
292288
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+
>
296292
<!-- any string surrounded by two % is replaced by that parameter value -->
297293
<some-package:config email-address="%app.admin_email%">
298294
<!-- ... -->
@@ -313,7 +309,6 @@ configuration file using a special syntax: wrap the parameter name in two ``%``
313309
]);
314310
};
315311
316-
317312
.. note::
318313

319314
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 ``%``
333328
334329
<!-- config/services.xml -->
335330
<parameters>
331+
<!-- Parsed as 'https://symfony.com/?foo=%s&amp;bar=%d' -->
336332
<parameter key="url_pattern">http://symfony.com/?foo=%%s&amp;bar=%%d</parameter>
337333
</parameters>
338334
339335
.. code-block:: php
340336
341337
// 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&amp;bar=%%d');
347-
};
338+
$container->parameters()
339+
// Parsed as 'https://symfony.com/?foo=%s&amp;bar=%d'
340+
->set('url_pattern', 'http://symfony.com/?foo=%%s&amp;bar=%%d')
341+
;
348342
349343
.. include:: /components/dependency_injection/_imports-parameters-note.rst.inc
350344

@@ -508,13 +502,14 @@ This example shows how you could configure the database connection using an env
508502
xsi:schemaLocation="http://symfony.com/schema/dic/services
509503
https://symfony.com/schema/dic/services/services-1.0.xsd
510504
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+
>
513507
<doctrine:config>
514508
<!-- by convention the env var names are always uppercase -->
515509
<doctrine:dbal url="%env(resolve:DATABASE_URL)%"/>
516510
</doctrine:config>
517511
512+
<!-- ... -->
518513
</container>
519514
520515
.. code-block:: php
@@ -528,6 +523,8 @@ This example shows how you could configure the database connection using an env
528523
// by convention the env var names are always uppercase
529524
'url' => '%env(resolve:DATABASE_URL)%',
530525
],
526+
527+
// ...
531528
]);
532529
};
533530
@@ -805,6 +802,8 @@ doesn't work for parameters:
805802
app.contents_dir: '...'
806803
807804
services:
805+
# ...
806+
808807
App\Service\MessageGenerator:
809808
arguments:
810809
$contentsDir: '%app.contents_dir%'
@@ -816,13 +815,15 @@ doesn't work for parameters:
816815
<container xmlns="http://symfony.com/schema/dic/services"
817816
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
818817
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+
>
821820
<parameters>
822821
<parameter key="app.contents_dir">...</parameter>
823822
</parameters>
824823
825824
<services>
825+
<!-- ... -->
826+
826827
<service id="App\Service\MessageGenerator">
827828
<argument key="$contentsDir">%app.contents_dir%</argument>
828829
</service>
@@ -838,11 +839,15 @@ doesn't work for parameters:
838839
839840
return static function (ContainerConfigurator $container) {
840841
$container->parameters()
841-
->set('app.contents_dir', '...');
842+
->set('app.contents_dir', '...')
843+
;
842844
843845
$container->services()
846+
// ...
847+
844848
->get(MessageGenerator::class)
845-
->arg('$contentsDir', '%app.contents_dir%');
849+
->arg('$contentsDir', '%app.contents_dir%')
850+
;
846851
};
847852
848853
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:
873878
<container xmlns="http://symfony.com/schema/dic/services"
874879
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
875880
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+
>
878883
<services>
879884
<defaults autowire="true" autoconfigure="true" public="false">
880885
<!-- pass this value to any $projectDir argument for any service
@@ -891,16 +896,15 @@ whenever a service/controller defines a ``$projectDir`` argument, use this:
891896
// config/services.php
892897
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
893898
894< 8A3F /code>-
use App\Controller\LuckyController;
895-
896899
return static function (ContainerConfigurator $container) {
897900
$container->services()
898901
->defaults()
899902
// pass this value to any $projectDir argument for any service
900903
// that's created in this file (including controller arguments)
901-
->bind('$projectDir', '%kernel.project_dir%');
904+
->bind('$projectDir', '%kernel.project_dir%')
902905
903-
// ...
906+
// ...
907+
;
904908
};
905909
906910
.. seealso::

0 commit comments

Comments
 (0)
0