From e95496669b3e1bf41a6f87b89a44f09c3983215b Mon Sep 17 00:00:00 2001 From: Ionut Enache Date: Wed, 5 Apr 2023 18:18:46 +0300 Subject: [PATCH] Update the example provided in the Development Versus Production: Environments section --- quick_tour/the_architecture.rst | 85 +++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 25 deletions(-) diff --git a/quick_tour/the_architecture.rst b/quick_tour/the_architecture.rst index 909dac32193..3e6eaaacaae 100644 --- a/quick_tour/the_architecture.rst +++ b/quick_tour/the_architecture.rst @@ -237,31 +237,66 @@ whenever needed. But what about when you deploy to production? We will need to hide those tools and optimize for speed! -This is solved by Symfony's *environment* system and there are three: ``dev``, ``prod`` -and ``test``. Based on the environment, Symfony loads different files in the ``config/`` -directory: - -.. code-block:: text - - config/ - ├─ services.yaml - ├─ ... - └─ packages/ - ├─ framework.yaml - ├─ ... - ├─ **dev/** - ├─ monolog.yaml - └─ ... - ├─ **prod/** - └─ monolog.yaml - └─ **test/** - ├─ framework.yaml - └─ ... - └─ routes/ - ├─ annotations.yaml - └─ **dev/** - ├─ twig.yaml - └─ web_profiler.yaml +This is solved by Symfony's *environment* system and there are three environments a +typical Symfony application begins with: ``dev``, ``prod``, and ``test``. You can define +options for specific environments in the configuration files from the ``config/`` +directory using the special ``when`` keyword: + +.. configuration-block:: + + .. code-block:: yaml + + # config/packages/routing.yaml + framework: + router: + utf8: true + + when@prod: + framework: + router: + strict_requirements: null + + .. code-block:: xml + + + + + + + + + + + + + + + + + .. code-block:: php + + // config/packages/framework.php + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + use Symfony\Config\FrameworkConfig; + + return static function (FrameworkConfig $framework, ContainerConfigurator $containerConfigurator) { + $framework->router() + ->utf8(true) + ; + + if ('prod' === $containerConfigurator->env()) { + $framework->router() + ->strictRequirements(null) + ; + } + }; This is a *powerful* idea: by changing one piece of configuration (the environment), your app is transformed from a debugging-friendly experience to one that's optimized