Skip to content

Commit d583107

Browse files
committed
Merge branch '5.4' into 6.2
* 5.4: Update the example provided in the Development Versus Production: Environments section
2 parents 013b6d1 + 8ee4dc1 commit d583107

File tree

1 file changed

+60
-25
lines changed

1 file changed

+60
-25
lines changed

quick_tour/the_architecture.rst

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -231,31 +231,66 @@ whenever needed.
231231
But what about when you deploy to production? We will need to hide those tools and
232232
optimize for speed!
233233

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

0 commit comments

Comments
 (0)