Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a15a43

Browse files
[Configuration] env() parameters notation
1 parent c2969fb commit 0a15a43

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

configuration.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,53 @@ To define the value of an env var, you have several options:
674674
* :ref:`Encrypt the value as a secret <configuration-secrets>`;
675675
* Set the value as a real environment variable in your shell or your web server.
676676

677+
It is possible to define an env var default value by defining a parameter with
678+
the same name. In the following example, we define a default value for the
679+
``SECRET`` env var if it has not been defined anywhere:
680+
681+
.. configuration-block::
682+
683+
.. code-block:: yaml
684+
685+
# config/packages/framework.yaml
686+
parameters:
687+
env(SECRET): 'some_secret'
688+
689+
# ...
690+
691+
.. code-block:: xml
692+
693+
<!-- config/packages/framework.xml -->
694+
<?xml version="1.0" encoding="UTF-8" ?>
695+
<container xmlns="http://symfony.com/schema/dic/services"
696+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
697+
xmlns:framework="http://symfony.com/schema/dic/symfony"
698+
xsi:schemaLocation="http://symfony.com/schema/dic/services
699+
https://symfony.com/schema/dic/services/services-1.0.xsd
700+
http://symfony.com/schema/dic/symfony
701+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
702+
703+
<parameters>
704+
<parameter key="env(SECRET)">some_secret</parameter>
705+
</parameters>
706+
707+
<!-- ... -->
708+
</container>
709+
710+
.. code-block:: php
711+
712+
// config/packages/framework.php
713+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
714+
715+
use Symfony\Component\DependencyInjection\ContainerBuilder;
716+
use Symfony\Config\FrameworkConfig;
717+
718+
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
719+
$container->setParameter('env(SECRET)', 'some_secret');
720+
721+
// ...
722+
};
723+
677724
.. tip::
678725

679726
Some hosts - like Platform.sh - offer easy `utilities to manage env vars`_

0 commit comments

Comments
 (0)