Skip to content

Update the example provided in the documentation for Development Versus Production: Environments #18167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 60 additions & 25 deletions quick_tour/the_architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:router utf8="true"/>
</framework:config>

<when env="prod">
<framework:config>
<framework:router strict-requirements="null"/>
</framework:config>
</when>
</container>

.. 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
Expand Down