Skip to content

Commit ba206a2

Browse files
committed
Fixes and improvements
1 parent be85f1e commit ba206a2

File tree

2 files changed

+46
-41
lines changed

2 files changed

+46
-41
lines changed

configuration.rst

+45-40
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ directory, which has this default structure:
2020
The ``routes.yaml`` file defines the :doc:`routing configuration </routing>`;
2121
the ``services.yaml`` file configures the services of the
2222
:doc:`service container </service_container>`; the ``bundles.php`` file enables/
23-
disables packages in your application and it's managed automatically by
23+
disables packages in your application and is managed automatically by
2424
:doc:`Symfony Flex </setup/flex>`.
2525

26-
The most important element inside ``config/`` is the ``packages/`` directory,
27-
which stores the configuration of every package installed in your application.
26+
You'll be working most in the ``config/packages/`` directory. This directory
27+
stores the configuration of every package installed in your application.
2828
Packages (also called "bundles" in Symfony and "plugins/modules" in other
2929
projects) add ready-to-use features to your projects.
3030

@@ -57,8 +57,8 @@ and throughout the Symfony documentation, all configuration examples will be
5757
shown in these three formats.
5858

5959
There isn't any practical difference between formats. In fact, Symfony
60-
transforms all of them into PHP before running the application, so there's not
61-
even any performance difference between them.
60+
transforms and caches all of them into PHP before running the application, so
61+
there's not even any performance difference between them.
6262

6363
YAML is used by default when installing packages because it's concise and very
6464
readable. These are the main advantages and disadvantages of each format:
@@ -188,8 +188,8 @@ reusable configuration value. By convention, parameters are defined under the
188188
// ...
189189
190190
Once defined, you can reference this parameter value from any other
191-
configuration file using a special syntax: wrap the parameter name with two
192-
``%`` (e.g. ``%app.admin_email%``):
191+
configuration file using a special syntax: wrap the parameter name in two ``%``
192+
(e.g. ``%app.admin_email%``):
193193

194194
.. configuration-block::
195195

@@ -215,9 +215,9 @@ configuration file using a special syntax: wrap the parameter name with two
215215
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
216216
217217
<!-- any string surrounded by two % is replaced by that parameter value -->
218-
<some-package email-address="%app.admin_email%">
218+
<some-package:config email-address="%app.admin_email%">
219219
<!-- ... -->
220-
</some-package>
220+
</some-package:config>
221221
</container>
222222
223223
.. code-block:: php
@@ -258,26 +258,19 @@ to behave differently at different times:
258258
* After deploying to **production**, you want that same application to be
259259
optimized for speed and only log errors.
260260

261-
In Symfony this is implemented with **environments**, which is a set of
262-
configuration files that define the application behavior. A typical Symfony
263-
application begins with three environments: ``dev`` (for local development),
264-
``prod`` (for production servers) and ``test`` (for
265-
:doc:`automated tests </testing>`). Each of them defines its own configuration
266-
files:
261+
The files stored in ``config/packages/`` are used by Symfony to configure the
262+
:doc:`application services </service_container>`. In other words, you can change
263+
the application behavior by changing which configuration files are loaded.
264+
That's the idea of Symfony's **configuration environments**.
267265

268-
* for the ``dev`` environment: ``config/packages/dev/``
269-
* for the ``prod`` environment: ``config/packages/prod/``
270-
* for the ``test`` environment: ``config/packages/test/``
271-
272-
In reality, each environment differs only somewhat from others. This means that
273-
all environments share a large base of common configurations, which is put in
274-
files directly in the ``config/packages/`` directory.
275-
276-
When running the application, Symfony loads the configuration files in this
277-
order (the last files can override the values set in the previous ones):
266+
A typical Symfony application begins with three environments: ``dev`` (for local
267+
development), ``prod`` (for production servers) and ``test`` (for
268+
:doc:`automated tests </testing>`). When running the application, Symfony loads
269+
the configuration files in this order (the last files can override the values
270+
set in the previous ones):
278271

279272
#. ``config/packages/*.yaml`` (and ``.xml`` and ``*.php`` files too);
280-
#. ``config/packages/<environment>/*.yaml`` (and ``.xml`` and ``*.php`` files too);
273+
#. ``config/packages/<environment-name>/*.yaml`` (and ``.xml`` and ``*.php`` files too);
281274
#. ``config/packages/services.yaml`` (and ``services.xml`` and ``services.php`` files too);
282275

283276
Take the ``framework`` package, installed by default, as an example:
@@ -292,6 +285,10 @@ Take the ``framework`` package, installed by default, as an example:
292285
is loaded to override some of the settings previously configured in
293286
``config/packages/framework.yaml``.
294287

288+
In reality, each environment differs only somewhat from others. This means that
289+
all environments share a large base of common configurations, which is put in
290+
files directly in the ``config/packages/`` directory.
291+
295292
.. seealso::
296293

297294
See the ``configureContainer()`` method of
@@ -311,10 +308,10 @@ Open the ``.env`` file and edit the value of the ``APP_ENV`` variable to change
311308
the environment in which the application runs. For example, to run the
312309
application in production:
313310

314-
```bash
315-
# .env
316-
APP_ENV=prod
317-
```
311+
.. code-block:: bash
312+
313+
# .env
314+
APP_ENV=prod
318315
319316
This value is used both for the web and for the console commands. However, you
320317
can override it for commands by setting the ``APP_ENV`` value before running them:
@@ -336,9 +333,9 @@ Creating a New Environment
336333
~~~~~~~~~~~~~~~~~~~~~~~~~~
337334

338335
The default three environments provided by Symfony are enough for most projects,
339-
but you can define more environments if you want to. For example, this is how
340-
you can define a ``staging`` environment where the client can test the project
341-
before going to production:
336+
but you can define your own environments too. For example, this is how you can
337+
define a ``staging`` environment where the client can test the project before
338+
going to production:
342339

343340
#. Create a configuration directory with the same name as the environment (in
344341
this case, ``config/packages/staging/``);
@@ -349,20 +346,27 @@ before going to production:
349346
#. Select the ``staging`` environment using the ``APP_ENV`` env var as explained
350347
in the previous section.
351348

349+
.. tip::
350+
351+
It's common for environments to be similar between each other, so you can
352+
use `symbolic links`_ between ``config/packages/<environment-name>/``
353+
directories to reuse the same configuration.
354+
352355
.. _config-env-vars:
353356

354357
Configuration Based on Environment Variables
355358
--------------------------------------------
356359

357360
Using `environment variables`_ (or "env vars" for short) is a common practice to
358-
configure sensitive options such as credentials and passwords. Instead of
359-
defining the values of those options in the configuration files, you add a
360-
reference to an environment variable which will be resolved at runtime (only
361-
once per request, to not impact performance).
361+
configure options that depend on where the application is run (e.g. the database
362+
credentials are usually different in production and in your local machine).
363+
364+
Instead of defining those as regular options, you can define them as environment
365+
variables and reference them in the configuration files using the special syntax
366+
``%env(ENV_VAR_NAME)%``. The values of these options are resolved at runtime
367+
(only once per request, to not impact performance).
362368

363-
Environment variables can be used in any configuration file and they are
364-
referenced with the special syntax ``%env(ENV_VAR_NAME)%``. This example shows
365-
how to configure the database connection using an env var:
369+
This example shows how to configure the database connection using an env var:
366370

367371
.. configuration-block::
368372

@@ -588,4 +592,5 @@ Learn more
588592
configuration/*
589593

590594
.. _`environment variables`: https://en.wikipedia.org/wiki/Environment_variable
595+
.. _`symbolic links`: https://en.wikipedia.org/wiki/Symbolic_link
591596
.. _`utilities to manage env vars`: https://symfony.com/doc/master/cloud/cookbooks/env.html

configuration/front_controllers_and_kernel.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ parameter used, for example, to turn Twig's debug mode on:
179179
<?xml version="1.0" encoding="UTF-8" ?>
180180
<container xmlns="http://symfony.com/schema/dic/services"
181181
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
182-
xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
182+
xmlns:twig="http://symfony.com/schema/dic/twig"
183183
xsi:schemaLocation="http://symfony.com/schema/dic/services
184184
https://symfony.com/schema/dic/services/services-1.0.xsd
185185
http://symfony.com/schema/dic/twig

0 commit comments

Comments
 (0)