Skip to content

Commit 8705f56

Browse files
committed
docs: improve description on Env Vars and Config values
1 parent 6c346b6 commit 8705f56

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

user_guide_src/source/database/configuration.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ default group's configuration settings. The values should be name following this
104104
database.default.password = '';
105105
database.default.database = 'ci4';
106106

107+
.. important:: You cannot add a new property by setting environment variables,
108+
nor change a scalar value to an array. See :ref:`env-var-replacements-for-data`.
109+
107110
**********************
108111
Explanation of Values:
109112
**********************

user_guide_src/source/general/configuration.rst

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ Configuration Classes and Environment Variables
150150
When you instantiate a configuration class, any *namespaced* environment variables
151151
are considered for merging into the configuration object's properties.
152152

153+
.. important:: You cannot add a new property by setting environment variables,
154+
nor change a scalar value to an array. See :ref:`env-var-replacements-for-data`.
155+
153156
If the prefix of a namespaced variable exactly matches the namespace of the configuration
154157
class, then the trailing part of the setting (after the dot) is treated as a configuration
155158
property. If it matches an existing configuration property, the environment variable's
@@ -180,20 +183,26 @@ Since v4.1.5, you can also write with underscores::
180183

181184
.. note:: When using the *short prefix* the property names must still exactly match the class defined name.
182185

186+
.. _env-var-replacements-for-data:
187+
183188
Environment Variables as Replacements for Data
184189
==============================================
185190

186191
It is very important to always remember that environment variables contained in your **.env** are
187-
**only replacements for existing data**. This means that you cannot expect to fill your **.env** with all
188-
the replacements for your configurations but have nothing to receive these replacements in the
189-
related configuration file(s).
192+
**only replacements for existing data**.
193+
194+
Simply put, you can change only the property value that exists in the Config class
195+
by setting it in your **.env**.
196+
197+
You cannot add a property that is not defined in the Config class, nor can you
198+
change it to an array if the value of the defined property is a scalar.
190199

191-
The **.env** only serves to fill or replace the values in your configuration files. That said, your
192-
configuration files should have a container or receiving property for those. Adding so many variables in
193-
your **.env** with nothing to contain them in the receiving end is useless.
200+
For example, you cannot just put ``app.myNewConfig = foo`` in your **.env** and
201+
expect your ``Config\App`` to magically have that property and value at run time.
194202

195-
Simply put, you cannot just put ``app.myNewConfig = foo`` in your **.env** and expect your ``Config\App``
196-
to magically have that property and value at run time.
203+
When you have the property ``$default = ['encrypt' => false]`` in your
204+
``Config\Database``, you cannot change the ``encrypt`` value to an array even if
205+
you put ``database.default.encrypt.ssl_verify = true`` in your **.env**.
197206

198207
Treating Environment Variables as Arrays
199208
========================================

0 commit comments

Comments
 (0)