Skip to content

Simplify configuration env var example #16575

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

Closed
wants to merge 4 commits into from
Closed
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
32 changes: 13 additions & 19 deletions configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -485,48 +485,42 @@ You can reference environment variables using the special syntax
``%env(ENV_VAR_NAME)%``. The values of these options are resolved at runtime
(only once per request, to not impact performance).

This example shows how you could configure the database connection using an env var:
This example shows how you could configure the application secret using an env var:

.. configuration-block::

.. code-block:: yaml

# config/packages/doctrine.yaml
doctrine:
dbal:
# by convention the env var names are always uppercase
url: '%env(resolve:DATABASE_URL)%'
# config/packages/framework.yaml
framework:
# by convention the env var names are always uppercase
secret: '%env(APP_SECRET)%'
# ...

.. code-block:: xml

<!-- config/packages/doctrine.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:doctrine="http://symfony.com/schema/dic/doctrine"
xmlns:framework="http://symfony.com/schema/dic/symfony
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
xmlns:framework="http://symfony.com/schema/dic/symfony
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/doctrine
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very unsure of those, may need careful review :s

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 509 should be kept :)
Line 507 should be changed to:
xmlns:framework="http://symfony.com/schema/dic/symfony
Finally line 510 and 511 should be changed to refer to:
http://symfony.com/schema/dic/symfony and
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd

https://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to keep all the lines here just replacing doctrine/doctrine part by symfony/symfony:

<?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/symfony
        https://symfony.com/schema/dic/symfony/symfony-1.0.xsd
">


<doctrine:config>
<!-- by convention the env var names are always uppercase -->
<doctrine:dbal url="%env(resolve:DATABASE_URL)%"/>
</doctrine:config>
<framework:config secret="%env(APP_SECRET)%"/>

</container>

.. code-block:: php

// config/packages/doctrine.php
// config/packages/framework.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container) {
$container->extension('doctrine', [
'dbal' => [
$container->extension('framework', [
'secret' => [
// by convention the env var names are always uppercase
'url' => '%env(resolve:DATABASE_URL)%',
'secret' => '%env(APP_SECRET)%',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one extra level here (framework.secret.secret), this should be like:

$container->extension('framework', [
    'secret' => '%env(APP_SECRET)%',
]);

],
]);
};
Expand Down