Skip to content

Add env default processor #10722

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 9, 2019
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
40 changes: 40 additions & 0 deletions configuration/external_parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,46 @@ Symfony provides the following env var processors:
.. versionadded:: 4.2
The ``key`` processor was introduced in Symfony 4.2.

``env(default:fallback_param:BAR)``
Retrieves the value of the parameter ``fallback_param`` when the of the ``BAR`` env var is not available:
Copy link
Contributor

Choose a reason for hiding this comment

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

This sentence seems to be missing some or having extra words :)

- Retrieves the value of the parameter ``fallback_param`` when the of the ``BAR`` env var is not available:
+ Retrieves the value of the parameter ``fallback_param`` when the ``BAR`` env var is not available:


.. configuration-block::

.. code-block:: yaml

# config/services.yaml
parameters:
private_key: '%env(default:raw_key:file:PRIVATE_KEY)%'
raw_key: '%env(PRIVATE_KEY)%'
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could put a hardcoded path/value for raw_key to make the example easier to understand. Using an env var as the default value of the env var value of another value makes my head explode 💥

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm.. Using the same variable to define both private key AND raw key was a IMO a great use case for the default processor and a convenient way to configure a bundle for instance.

If we remove the double use of the same variable, we should find a totally example. What's about case where "injected secret file does not exists" (or variable not provided at all)?

parameters:
  app.secrets: '%env(default:public_secrets:json:file:SECRETS_FILE)%'
  public_secrets:
    db: root
    api: pass
--

# if PRIVATE_KEY is not a valid file path, the content of raw_key is returned.

.. 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="private_key">%env(default:raw_key:file:PRIVATE_KEY)%</parameter>
<parameter key="raw_key">%env(PRIVATE_KEY)%</parameter>
</parameters>
</container>

.. code-block:: php

// config/services.php
$container->setParameter('private_key', '%env(default:raw_key:file:PRIVATE_KEY)%');
$container->setParameter('raw_key', '%env(PRIVATE_KEY)%');

.. versionadded:: 4.3
The ``default`` processor was introduced in Symfony 4.3.

It is also possible to combine any number of processors:

.. code-block:: yaml
Expand Down