Skip to content

Commit 4bc7793

Browse files
committed
Removed DotEnv component docs
1 parent e9f6127 commit 4bc7793

File tree

3 files changed

+57
-173
lines changed

3 files changed

+57
-173
lines changed

_build/redirection_map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,4 @@
481481
/components/routing https://github.com/symfony/routing
482482
/doctrine/pdo_session_storage /session/database
483483
/doctrine/mongodb_session_storage /session/database
484+
/components/dotenv https://github.com/symfony/dotenv

components/dotenv.rst

Lines changed: 0 additions & 173 deletions
This file was deleted.

configuration.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,62 @@ In addition to your own env vars, this ``.env`` file also contains the env vars
543543
defined by the third-party packages installed in your application (they are
544544
added automatically by :ref:`Symfony Flex <symfony-flex>` when installing packages).
545545

546+
.env File Syntax
547+
................
548+
549+
Add comments by prefixing them with ``#``:
550+
551+
.. code-block:: bash
552+
553+
# database credentials
554+
DB_USER=root
555+
DB_PASS=pass # this is the secret password
556+
557+
Use environment variables in values by prefixing variables with ``$``:
558+
559+
.. code-block:: bash
560+
561+
DB_USER=root
562+
DB_PASS=${DB_USER}pass # include the user as a password prefix
563+
564+
.. caution::
565+
566+
The order is important when some env var depends on the value of other env
567+
vars. In the above example, ``DB_PASS`` must be defined after ``DB_USER``.
568+
Moreover, if you define multiple ``.env`` files and put ``DB_PASS`` first,
569+
its value will depend on the ``DB_USER`` value defined in other files
570+
instead of the value defined in this file.
571+
572+
Define a default value in case the environment variable is not set:
573+
574+
.. code-block:: bash
575+
576+
DB_USER=
577+
DB_PASS=${DB_USER:-root}pass # results in DB_PASS=rootpass
578+
579+
.. versionadded:: 4.4
580+
581+
The support for default values has been introduced in Symfony 4.4.
582+
583+
Embed commands via ``$()`` (not supported on Windows):
584+
585+
.. code-block:: bash
586+
587+
START_TIME=$(date)
588+
589+
.. caution::
590+
591+
Using ``$()`` might not work depending on your shell.
592+
593+
.. tip::
594+
595+
As a ``.env`` file is a regular shell script, you can ``source`` it in
596+
your own shell scripts:
597+
598+
.. code-block:: terminal
599+
600+
$ source .env
601+
546602
.. _configuration-multiple-env-files:
547603

548604
Overriding Environment Values via .env.local

0 commit comments

Comments
 (0)