Skip to content

Commit 68aa9e1

Browse files
committed
Ensure config blocks are consistent
1 parent 76481e2 commit 68aa9e1

11 files changed

+302
-207
lines changed

bundles/best_practices.rst

+9-3
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ The end user can provide values in any configuration file:
421421
<container xmlns="http://symfony.com/schema/dic/services"
422422
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
423423
xsi:schemaLocation="http://symfony.com/schema/dic/services
424-
https://symfony.com/schema/dic/services/services-1.0.xsd">
425-
424+
https://symfony.com/schema/dic/services/services-1.0.xsd"
425+
>
426426
<parameters>
427427
<parameter key="acme_blog.author.email">[email protected]</parameter>
428428
</parameters>
@@ -432,7 +432,13 @@ The end user can provide values in any configuration file:
432432
.. code-block:: php
433433
434434
// config/services.php
435-
$container->setParameter('acme_blog.author.email', '[email protected]');
435+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
436+
437+
return static function (ContainerConfigurator $container) {
438+
$container->parameters()
439+
->set('acme_blog.author.email', '[email protected]')
440+
;
441+
};
436442
437443
Retrieve the configuration parameters in your code from the container::
438444

bundles/configuration.rst

+32-20
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,37 @@ as integration of other related components:
2020

2121
.. code-block:: yaml
2222
23+
# config/packages/framework.yaml
2324
framework:
2425
form: true
2526
2627
.. code-block:: xml
2728
29+
<!-- config/packages/framework.xml -->
2830
<?xml version="1.0" encoding="UTF-8" ?>
2931
<container xmlns="http://symfony.com/schema/dic/services"
32+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3033
xmlns:framework="http://symfony.com/schema/dic/symfony"
3134
xsi:schemaLocation="http://symfony.com/schema/dic/services
3235
https://symfony.com/schema/dic/services/services-1.0.xsd
3336
http://symfony.com/schema/dic/symfony
34-
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
35-
37+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
38+
>
3639
<framework:config>
3740
<framework:form/>
3841
</framework:config>
3942
</container>
4043
4144
.. code-block:: php
4245
43-
$container->loadFromExtension('framework', [
44-
'form' => true,
45-
]);
46+
// config/packages/framework.php
47+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
48+
49+
return static function (ContainerConfigurator $container) {
50+
$container->extension('framework', [
51+
'form' => true,
52+
]);
53+
};
4654
4755
Using the Bundle Extension
4856
--------------------------
@@ -69,24 +77,28 @@ can add some configuration that looks like this:
6977
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7078
xmlns:acme-social="http://example.org/schema/dic/acme_social"
7179
xsi:schemaLocation="http://symfony.com/schema/dic/services
72-
https://symfony.com/schema/dic/services/services-1.0.xsd">
73-
80+
https://symfony.com/schema/dic/services/services-1.0.xsd"
81+
>
7482
<acme-social:config>
75-
<acme-social:twitter client-id="123" client-secret="your_secret"/>
83+
<acme-social:twitter client-id="123"
84+
client-secret="your_secret"
85+
/>
7686
</acme-social:config>
77-
78-
<!-- ... -->
7987
</container>
8088
8189
.. code-block:: php
8290
8391
// config/packages/acme_social.php
84-
$container->loadFromExtension('acme_social', [
85-
'twitter' => [
86-
'client_id' => 123,
87-
'client_secret' => 'your_secret',
88-
],
89-
]);
92+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
93+
94+
return static function (ContainerConfigurator $container) {
95+
$container->extension('acme_social', [
96+
'twitter' => [
97+
'client_id' => 123,
98+
'client_secret' => 'your_secret',
99+
],
100+
]);
101+
};
90102
91103
The basic idea is that instead of having the user override individual
92104
parameters, you let the user configure just a few, specifically created,
@@ -242,8 +254,8 @@ For example, imagine your bundle has the following example config:
242254
<container xmlns="http://symfony.com/schema/dic/services"
243255
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
244256
xsi:schemaLocation="http://symfony.com/schema/dic/services
245-
https://symfony.com/schema/dic/services/services-1.0.xsd">
246-
257+
https://symfony.com/schema/dic/services/services-1.0.xsd"
258+
>
247259
<services>
248260
<service id="acme.social.twitter_client" class="Acme\SocialBundle\TwitterClient">
249261
<argument></argument> <!-- will be filled in with client_id dynamically -->
@@ -423,8 +435,8 @@ Assuming the XSD file is called ``hello-1.0.xsd``, the schema location will be
423435
xsi:schemaLocation="http://symfony.com/schema/dic/services
424436
https://symfony.com/schema/dic/services/services-1.0.xsd
425437
http://acme_company.com/schema/dic/hello
426-
https://acme_company.com/schema/dic/hello/hello-1.0.xsd">
427-
438+
https://acme_company.com/schema/dic/hello/hello-1.0.xsd"
439+
>
428440
<acme-hello:config>
429441
<!-- ... -->
430442
</acme-hello:config>

bundles/override.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ to a new validation group:
139139
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
140140
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
141141
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
142-
https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
143-
142+
https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"
143+
>
144144
<class name="FOS\UserBundle\Model\User">
145145
<property name="plainPassword">
146146
<constraint name="NotBlank">

bundles/prepend_extension.rst

+18-12
Original file line numberDiff line numberDiff line change
@@ -127,29 +127,35 @@ registered and the ``entity_manager_name`` setting for ``acme_hello`` is set to
127127
http://example.org/schema/dic/acme_something
128128
https://example.org/schema/dic/acme_something/acme_something-1.0.xsd
129129
http://example.org/schema/dic/acme_other
130-
https://example.org/schema/dic/acme_something/acme_other-1.0.xsd">
131-
130+
https://example.org/schema/dic/acme_something/acme_other-1.0.xsd"
131+
>
132132
<acme-something:config use-acme-goodbye="false">
133133
<!-- ... -->
134134
<acme-something:entity-manager-name>non_default</acme-something:entity-manager-name>
135135
</acme-something:config>
136136
137-
<acme-other:config use-acme-goodbye="false"/>
137+
<acme-other:config use-acme-goodbye="false">
138+
<!-- ... -->
139+
</acme-other:config>
138140
139141
</container>
140142
141143
.. code-block:: php
142144
143145
// config/packages/acme_something.php
144-
$container->loadFromExtension('acme_something', [
145-
// ...
146-
'use_acme_goodbye' => false,
147-
'entity_manager_name' => 'non_default',
148-
]);
149-
$container->loadFromExtension('acme_other', [
150-
// ...
151-
'use_acme_goodbye' => false,
152-
]);
146+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
147+
148+
return static function (ContainerConfigurator $container) {
149+
$container->extension('acme_something', [
150+
// ...
151+
'use_acme_goodbye' => false,
152+
'entity_manager_name' => 'non_default',
153+
]);
154+
$container->extension('acme_other', [
155+
// ...
156+
'use_acme_goodbye' => false,
157+
]);
158+
};
153159
154160
More than one Bundle using PrependExtensionInterface
155161
----------------------------------------------------

0 commit comments

Comments
 (0)