Skip to content

Ensure config blocks are consistent #16992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions bundles/best_practices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ The end user can provide values in any configuration file:
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">

https://symfony.com/schema/dic/services/services-1.0.xsd"
>
<parameters>
<parameter key="acme_blog.author.email">fabien@example.com</parameter>
</parameters>
Expand All @@ -432,7 +432,13 @@ The end user can provide values in any configuration file:
.. code-block:: php

// config/services.php
$container->setParameter('acme_blog.author.email', 'fabien@example.com');
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container) {
$container->parameters()
->set('acme_blog.author.email', 'fabien@example.com')
;
};

Retrieve the configuration parameters in your code from the container::

Expand Down
52 changes: 32 additions & 20 deletions bundles/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,37 @@ as integration of other related components:

.. code-block:: yaml

# config/packages/framework.yaml
framework:
form: true

.. code-block:: xml

<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
>
<framework:config>
<framework:form/>
</framework:config>
</container>

.. code-block:: php

$container->loadFromExtension('framework', [
'form' => true,
]);
// config/packages/framework.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container) {
$container->extension('framework', [
'form' => true,
]);
};

Using the Bundle Extension
--------------------------
Expand All @@ -69,24 +77,28 @@ can add some configuration that looks like this:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:acme-social="http://example.org/schema/dic/acme_social"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">

https://symfony.com/schema/dic/services/services-1.0.xsd"
>
<acme-social:config>
<acme-social:twitter client-id="123" client-secret="your_secret"/>
<acme-social:twitter client-id="123"
client-secret="your_secret"
/>
</acme-social:config>

<!-- ... -->
</container>

.. code-block:: php

// config/packages/acme_social.php
$container->loadFromExtension('acme_social', [
'twitter' => [
'client_id' => 123,
'client_secret' => 'your_secret',
],
]);
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container) {
$container->extension('acme_social', [
'twitter' => [
'client_id' => 123,
'client_secret' => 'your_secret',
],
]);
};

The basic idea is that instead of having the user override individual
parameters, you let the user configure just a few, specifically created,
Expand Down Expand Up @@ -242,8 +254,8 @@ For example, imagine your bundle has the following example config:
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">

https://symfony.com/schema/dic/services/services-1.0.xsd"
>
<services>
<service id="acme.social.twitter_client" class="Acme\SocialBundle\TwitterClient">
<argument></argument> <!-- will be filled in with client_id dynamically -->
Expand Down Expand Up @@ -423,8 +435,8 @@ Assuming the XSD file is called ``hello-1.0.xsd``, the schema location will be
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://acme_company.com/schema/dic/hello
https://acme_company.com/schema/dic/hello/hello-1.0.xsd">

https://acme_company.com/schema/dic/hello/hello-1.0.xsd"
>
<acme-hello:config>
<!-- ... -->
</acme-hello:config>
Expand Down
4 changes: 2 additions & 2 deletions bundles/override.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ to a new validation group:
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">

https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"
>
<class name="FOS\UserBundle\Model\User">
<property name="plainPassword">
<constraint name="NotBlank">
Expand Down
30 changes: 18 additions & 12 deletions bundles/prepend_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,35 @@ registered and the ``entity_manager_name`` setting for ``acme_hello`` is set to
http://example.org/schema/dic/acme_something
https://example.org/schema/dic/acme_something/acme_something-1.0.xsd
http://example.org/schema/dic/acme_other
https://example.org/schema/dic/acme_something/acme_other-1.0.xsd">

https://example.org/schema/dic/acme_something/acme_other-1.0.xsd"
>
<acme-something:config use-acme-goodbye="false">
<!-- ... -->
<acme-something:entity-manager-name>non_default</acme-something:entity-manager-name>
</acme-something:config>

<acme-other:config use-acme-goodbye="false"/>
<acme-other:config use-acme-goodbye="false">
<!-- ... -->
</acme-other:config>

</container>

.. code-block:: php

// config/packages/acme_something.php
$container->loadFromExtension('acme_something', [
// ...
'use_acme_goodbye' => false,
'entity_manager_name' => 'non_default',
]);
$container->loadFromExtension('acme_other', [
// ...
'use_acme_goodbye' => false,
]);
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container) {
$container->extension('acme_something', [
// ...
'use_acme_goodbye' => false,
'entity_manager_name' => 'non_default',
]);
$container->extension('acme_other', [
// ...
'use_acme_goodbye' => false,
]);
};

More than one Bundle using PrependExtensionInterface
----------------------------------------------------
Expand Down
Loading