Skip to content

Add missing configurations in XML and PHP formats #14777

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
Jan 7, 2021
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
96 changes: 82 additions & 14 deletions configuration/env_var_processors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,42 @@ Symfony provides the following env var processors:
``env(csv:FOO)``
Decodes the content of ``FOO``, which is a CSV-encoded string:

.. code-block:: yaml
.. configuration-block::

parameters:
env(TRUSTED_HOSTS): "10.0.0.1, 10.0.0.2"
framework:
trusted_hosts: '%env(csv:TRUSTED_HOSTS)%'
.. code-block:: yaml

# config/packages/framework.yaml
parameters:
env(TRUSTED_HOSTS): "10.0.0.1, 10.0.0.2"
framework:
trusted_hosts: '%env(csv:TRUSTED_HOSTS)%'

.. 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">

<parameters>
<parameter key="env(TRUSTED_HOSTS)">["10.0.0.1", "10.0.0.2"]</parameter>
</parameters>

<framework:config trusted-hosts="%env(csv:TRUSTED_HOSTS)%"/>
</container>

.. code-block:: php

// config/packages/framework.php
$container->setParameter('env(TRUSTED_HOSTS)', '["10.0.0.1", "10.0.0.2"]');
$container->loadFromExtension('framework', [
'trusted_hosts' => '%env(csv:TRUSTED_HOSTS)%',
]);

``env(file:FOO)``
Returns the contents of a file whose path is the value of the ``FOO`` env var:
Expand Down Expand Up @@ -627,16 +657,54 @@ Symfony provides the following env var processors:

It is also possible to combine any number of processors:

.. code-block:: yaml
.. configuration-block::

.. code-block:: yaml

parameters:
env(AUTH_FILE): "%kernel.project_dir%/config/auth.json"
google:
# 1. gets the value of the AUTH_FILE env var
# 2. replaces the values of any config param to get the config path
# 3. gets the content of the file stored in that path
# 4. JSON-decodes the content of the file and returns it
auth: '%env(json:file:resolve:AUTH_FILE)%'
# config/packages/framework.yaml
parameters:
env(AUTH_FILE): "%kernel.project_dir%/config/auth.json"
google:
# 1. gets the value of the AUTH_FILE env var
# 2. replaces the values of any config param to get the config path
# 3. gets the content of the file stored in that path
# 4. JSON-decodes the content of the file and returns it
auth: '%env(json:file:resolve:AUTH_FILE)%'

.. 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">

<parameters>
<parameter key="env(AUTH_FILE)">%kernel.project_dir%/config/auth.json</parameter>
</parameters>

<!-- 1. gets the value of the AUTH_FILE env var -->
<!-- 2. replaces the values of any config param to get the config path -->
<!-- 3. gets the content of the file stored in that path -->
<!-- 4. JSON-decodes the content of the file and returns it -->
<google auth="%env(json:file:resolve:AUTH_FILE)%"/>
</container>

.. code-block:: php

// config/packages/framework.php
$container->setParameter('env(AUTH_FILE)', '%kernel.project_dir%/config/auth.json');
// 1. gets the value of the AUTH_FILE env var
// 2. replaces the values of any config param to get the config path
// 3. gets the content of the file stored in that path
// 4. JSON-decodes the content of the file and returns it
$container->loadFromExtension('google', [
'auth' => '%env(json:file:resolve:AUTH_FILE)%',
]);

Custom Environment Variable Processors
--------------------------------------
Expand Down