8000 minor #10722 Add env default processor (jderusse) · symfony/symfony-docs@c1bcf07 · GitHub
[go: up one dir, main page]

Skip to content

Commit c1bcf07

Browse files
committed
minor #10722 Add env default processor (jderusse)
This PR was merged into the master branch. Discussion ---------- Add env default processor This PR documents symfony/symfony#28976 Commits ------- 8d3afcc Add env default processor
2 parents 9c1f0a3 + 8d3afcc commit c1bcf07

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

configuration/external_parameters.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,46 @@ Symfony provides the following env var processors:
497497
$container->setParameter('env(SECRETS_FILE)', '/opt/application/.secrets.json');
498498
$container->setParameter('database_password', '%env(key:database_password:json:file:SECRETS_FILE)%');
499499
500+
``env(default:fallback_param:BAR)``
501+
Retrieves the value of the parameter ``fallback_param`` when the of the ``BAR`` env var is not available:
502+
503+
.. configuration-block::
504+
505+
.. code-block:: yaml
506+
507+
# config/services.yaml
508+
parameters:
509+
private_key: '%env(default:raw_key:file:PRIVATE_KEY)%'
510+
raw_key: '%env(PRIVATE_KEY)%'
511+
# if PRIVATE_KEY is not a valid file path, the content of raw_key is returned.
512+
513+
.. code-block:: xml
514+
515+
<!-- config/services.xml -->
516+
<?xml version="1.0" encoding="UTF-8" ?>
517+
<container xmlns="http://symfony.com/schema/dic/services"
518+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
519+
xmlns:framework="http://symfony.com/schema/dic/symfony"
520+
xsi:schemaLocation="http://symfony.com/schema/dic/services
521+
http://symfony.com/schema/dic/services/services-1.0.xsd
522+
http://symfony.com/schema/dic/symfony
523+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
524+
525+
<parameters>
526+
<parameter key="private_key">%en A827 v(default:raw_key:file:PRIVATE_KEY)%</parameter>
527+
<parameter key="raw_key">%env(PRIVATE_KEY)%</parameter>
528+
</parameters>
529+
</container>
530+
531+
.. code-block:: php
532+
533+
// config/services.php
534+
$container->setParameter('private_key', '%env(default:raw_key:file:PRIVATE_KEY)%');
535+
$container->setParameter('raw_key', '%env(PRIVATE_KEY)%');
536+
537+
.. versionadded:: 4.3
538+
The ``default`` processor was introduced in Symfony 4.3.
539+
500540
It is also possible to combine any number of processors:
501541

502542
.. code-block:: yaml

0 commit comments

Comments
 (0)
0