Skip to content

Commit f306f85

Browse files
committed
Ensure config blocks are consistent
1 parent b5eaf1b commit f306f85

11 files changed

+290
-202
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 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

+31-20
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,36 @@ 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"
3032
xmlns:framework="http://symfony.com/schema/dic/symfony"
3133
xsi:schemaLocation="http://symfony.com/schema/dic/services
3234
https://symfony.com/schema/dic/services/services-1.0.xsd
3335
http://symfony.com/schema/dic/symfony
34-
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
35-
36+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
37+
>
3638
<framework:config>
3739
<framework:form/>
3840
</framework:config>
3941
</container>
4042
4143
.. code-block:: php
4244
43-
$container->loadFromExtension('framework', [
44-
'form' => true,
45-
]);
45+
// config/packages/framework.php
46+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
47+
48+
return function (ContainerConfigurator $container) {
49+
$container->extension('framework', [
50+
'form' => true,
51+
]);
52+
};
4653
4754
Using the Bundle Extension
4855
--------------------------
@@ -69,24 +76,28 @@ can add some configuration that looks like this:
6976
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7077
xmlns:acme-social="http://example.org/schema/dic/acme_social"
7178
xsi:schemaLocation="http://symfony.com/schema/dic/services
72-
https://symfony.com/schema/dic/services/services-1.0.xsd">
73-
79+
https://symfony.com/schema/dic/services/services-1.0.xsd"
80+
>
7481
<acme-social:config>
75-
<acme-social:twitter client-id="123" client-secret="your_secret"/>
82+
<acme-social:twitter client-id="123"
83+
client-secret="your_secret"
84+
/>
7685
</acme-social:config>
77-
78-
<!-- ... -->
7986
</container>
8087
8188
.. code-block:: php
8289
8390
// config/packages/acme_social.php
84-
$container->loadFromExtension('acme_social', [
85-
'twitter' => [
86-
'client_id' => 123,
87-
'client_secret' => 'your_secret',
88-
],
89-
]);
91+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
92+
93+
return function (ContainerConfigurator $container) {
94+
$container->extension('acme_social', [
95+
'twitter' => [
96+
'client_id' => 123,
97+
'client_secret' => 'your_secret',
98+
],
99+
]);
100+
};
90101
91102
The basic idea is that instead of having the user override individual
92103
parameters, you let the user configure just a few, specifically created,
@@ -242,8 +253,8 @@ For example, imagine your bundle has the following example config:
242253
<container xmlns="http://symfony.com/schema/dic/services"
243254
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
244255
xsi:schemaLocation="http://symfony.com/schema/dic/services
245-
https://symfony.com/schema/dic/services/services-1.0.xsd">
246-
256+
https://symfony.com/schema/dic/services/services-1.0.xsd"
257+
>
247258
<services>
248259
<service id="acme.social.twitter_client" class="Acme\SocialBundle\TwitterClient">
249260
<argument></argument> <!-- will be filled in with client_id dynamically -->
@@ -423,8 +434,8 @@ Assuming the XSD file is called ``hello-1.0.xsd``, the schema location will be
423434
xsi:schemaLocation="http://symfony.com/schema/dic/services
424435
https://symfony.com/schema/dic/services/services-1.0.xsd
425436
http://acme_company.com/schema/dic/hello
426-
https://acme_company.com/schema/dic/hello/hello-1.0.xsd">
427-
437+
https://acme_company.com/schema/dic/hello/hello-1.0.xsd"
438+
>
428439
<acme-hello:config>
429440
<!-- ... -->
430441
</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 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)