Skip to content

Commit 0db083a

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: Update invalid return custom processor [Configuration] `env()` parameters notation
2 parents 3d5aa3f + d83bfd1 commit 0db083a

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

configuration.rst

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

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+
688738
.. tip::
689739

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

logging/processors.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ using a processor::
3636
try {
3737
$session = $this->requestStack->getSession();
3838
} catch (SessionNotFoundException $e) {
39-
return;
39+
return $record;
4040
}
4141
if (!$session->isStarted()) {
4242
return $record;

0 commit comments

Comments
 (0)