@@ -237,31 +237,66 @@ whenever needed.
237237But what about when you deploy to production? We will need to hide those tools and
238238optimize for speed!
239239
240- This is solved by Symfony's *environment * system and there are three: ``dev ``, ``prod ``
241- and ``test ``. Based on the environment, Symfony loads different files in the ``config/ ``
242- directory:
243-
244- .. code-block :: text
245-
246- config/
247- ├─ services.yaml
248- ├─ ...
249- └─ packages/
250- ├─ framework.yaml
251- ├─ ...
252- ├─ **dev/**
253- ├─ monolog.yaml
254- └─ ...
255- ├─ **prod/**
256- └─ monolog.yaml
257- └─ **test/**
258- ├─ framework.yaml
259- └─ ...
260- └─ routes/
261- ├─ annotations.yaml
262- └─ **dev/**
263- ├─ twig.yaml
264- └─ web_profiler.yaml
240+ This is solved by Symfony's *environment * system and there are three environments a
241+ typical Symfony application begins with: ``dev ``, ``prod ``, and ``test ``. You can define
242+ options for specific environments in the configuration files from the ``config/ ``
243+ directory using the special ``when `` keyword:
244+
245+ .. configuration-block ::
246+
247+ .. code-block :: yaml
248+
249+ # config/packages/routing.yaml
250+ framework :
251+ router :
252+ utf8 : true
253+
254+ when@prod :
255+ framework :
256+ router :
257+ strict_requirements : null
258+
259+ .. code-block :: xml
260+
261+ <!-- config/packages/framework.xml -->
262+ <?xml version =" 1.0" encoding =" UTF-8" ?>
263+ <container xmlns =" http://symfony.com/schema/dic/services"
264+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
265+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
266+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
267+ https://symfony.com/schema/dic/services/services-1.0.xsd
268+ http://symfony.com/schema/dic/symfony
269+ https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
270+
271+ <framework : config >
272+ <framework : router utf8 =" true" />
273+ </framework : config >
274+
275+ <when env =" prod" >
276+ <framework : config >
277+ <framework : router strict-requirements =" null" />
278+ </framework : config >
279+ </when >
280+ </container >
281+
282+ .. code-block :: php
283+
284+ // config/packages/framework.php
285+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
286+
287+ use Symfony\Config\FrameworkConfig;
288+
289+ return static function (FrameworkConfig $framework, ContainerConfigurator $containerConfigurator) {
290+ $framework->router()
291+ ->utf8(true)
292+ ;
293+
294+ if ('prod' === $containerConfigurator->env()) {
295+ $framework->router()
296+ ->strictRequirements(null)
297+ ;
298+ }
299+ };
265300
266301 This is a *powerful * idea: by changing one piece of configuration (the environment),
267302your app is transformed from a debugging-friendly experience to one that's optimized
0 commit comments