Skip to content

Added key env processor to docs #10009

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 2 commits into from
Jul 4, 2018
Merged
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/external_parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,47 @@ Symfony provides the following env var processors:
'auth' => '%env(file:AUTH_FILE)%',
));

``env(key:FOO:BAR)``
Retrieves the value associated with the key ``FOO`` from the array whose
contents are stored in the ``BAR`` env var:

.. configuration-block::

.. code-block:: yaml

# config/services.yaml
parameters:
env(SECRETS_FILE): '/opt/application/.secrets.json'
database_password: '%env(key:database_password:json:file:SECRETS_FILE)%'
# 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
http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

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

.. code-block:: php

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

.. versionadded:: 4.2
The ``key`` processor was introduced in Symfony 4.2.

It is also possible to combine any number of processors:

.. code-block:: yaml
Expand Down