-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
https://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/doctrine | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very unsure of those, may need careful review :s There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line 509 should be kept :) |
||
https://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd"> | ||
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to keep all the lines here just replacing <?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' => [ | ||
94noni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// by convention the env var names are always uppercase | ||
'url' => '%env(resolve:DATABASE_URL)%', | ||
'secret' => '%env(APP_SECRET)%', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is one extra level here ( $container->extension('framework', [
'secret' => '%env(APP_SECRET)%',
]); |
||
], | ||
]); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.