@@ -685,6 +685,56 @@ To define the value of an env var, you have several options:
685
685
* :ref: `Encrypt the value as a secret <configuration-secrets >`;
686
686
* Set the value as a real environment variable in your shell or your web server.
687
687
688
+ If your application tries to use an env var that hasn't been defined, you'll see
689
+ an exception. You can prevent that by defining a default value for the env var.
690
+ To do so, define a parameter with the same name as the env var using this syntax:
691
+
692
+ .. configuration-block ::
693
+
694
+ .. code-block :: yaml
695
+
696
+ # config/packages/framework.yaml
697
+ parameters :
698
+ # if the SECRET env var value is not defined anywhere, Symfony uses this value
699
+ env(SECRET) : ' some_secret'
700
+
701
+ # ...
702
+
703
+ .. code-block :: xml
704
+
705
+ <!-- config/packages/framework.xml -->
706
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
707
+ <container xmlns =" http://symfony.com/schema/dic/services"
708
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
709
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
710
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
711
+ https://symfony.com/schema/dic/services/services-1.0.xsd
712
+ http://symfony.com/schema/dic/symfony
713
+ https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
714
+
715
+ <parameters >
716
+ <!-- if the SECRET env var value is not defined anywhere, Symfony uses this value -->
717
+ <parameter key =" env(SECRET)" >some_secret</parameter >
718
+ </parameters >
719
+
720
+ <!-- ... -->
721
+ </container >
722
+
723
+ .. code-block :: php
724
+
725
+ // config/packages/framework.php
726
+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
727
+
728
+ use Symfony\Component\DependencyInjection\ContainerBuilder;
729
+ use Symfony\Config\FrameworkConfig;
730
+
731
+ return static function (ContainerBuilder $container, FrameworkConfig $framework) {
732
+ // if the SECRET env var value is not defined anywhere, Symfony uses this value
733
+ $container->setParameter('env(SECRET)', 'some_secret');
734
+
735
+ // ...
736
+ };
737
+
688
738
.. tip ::
689
739
690
740
Some hosts - like Platform.sh - offer easy `utilities to manage env vars `_
0 commit comments