Skip to content

Add docs for the yaml env var processor #11321

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 2 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
41 changes: 41 additions & 0 deletions configuration/environment_variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,47 @@ Symfony provides the following env var processors:
'trusted_hosts' => '%env(json:TRUSTED_HOSTS)%',
]);

``env(yaml:FOO)``
Decodes the content of ``FOO``, which is a YAML encoded string. It returns
either an array or ``null``. Mostly useful in combination with
``file``:

.. code-block:: yaml

# config/services.yaml
parameters:
env(SECRETS_FILE): '/opt/application/.secrets.yaml'
database_password: '%env(key:database_password:yaml:file:SECRETS_FILE)%'
Copy link
Contributor

Choose a reason for hiding this comment

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

could we change the example and remove the key:database_password processor here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@OskarStark To make the example more concise?

Would you ever use an array value as such?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm not sure, I haven’t any other example

# if SECRETS_FILE contents are: 'database_password: secret' it returns "secret"

.. code-block:: xml

<!-- config/services.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">

<parameters>
<parameter key="env(SECRETS_FILE)">/opt/application/.secrets.yaml</parameter>
<parameter key="database_password">%env(key:database_password:yaml:file:SECRETS_FILE)%</parameter>
</parameters>
</container>

.. code-block:: php

// config/services.php
$container->setParameter('env(SECRETS_FILE)', '/opt/application/.secrets.yaml');
$container->setParameter('database_password', '%env(key:database_password:yaml:file:SECRETS_FILE)%');

.. versionadded:: 4.3

The ``yaml`` processor was introduced in Symfony 4.3.

``env(resolve:FOO)``
Replaces the string ``FOO`` by the value of a config parameter with the
same name:
Expand Down