From 007dd645323ef518a309f40d77472ea693b958fe Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Wed, 27 Nov 2019 11:55:09 +0100 Subject: [PATCH] adding section about datetime prefix in EnvVarProcessor --- configuration/env_var_processors.rst | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/configuration/env_var_processors.rst b/configuration/env_var_processors.rst index 83eafef37aa..aab0a4ac864 100644 --- a/configuration/env_var_processors.rst +++ b/configuration/env_var_processors.rst @@ -604,6 +604,57 @@ Symfony provides the following env var processors: ], ]); +``env(datetime:NOW)`` + Instantiates a ``DateTime`` object with the given time string. + + .. code-block:: bash + + # .env + NOW="11-21-2018 08:00" + + .. configuration-block:: + + .. code-block:: yaml + + # config/services.yaml + services: + # if NOW is not set, the DateTime will be using system time + App\Service\Clock: + $now: '%env(datetime:default::NOW)%' + + .. code-block:: xml + + + + + + + + %env(datetime:default::NOW)% + + + + + .. code-block:: php + + // config/services.php + use App\Service\Clock + + // if NOW is not set, the DateTime will be using system time + $container->getDefinition(Clock::class) + ->setArgument('$now', '%env(datetime:default::NOW)%'); + + .. note:: + + It is also possible to use ``DateTimeImmutable`` instead by + using ``datetime_immutable`` as prefix. + It is also possible to combine any number of processors: .. code-block:: yaml