Skip to content

Commit feaf346

Browse files
committed
minor #7589 Proposed a new "best practice" for parameter naming (javiereguiluz)
This PR was merged into the 2.7 branch. Discussion ---------- Proposed a new "best practice" for parameter naming This fixes #7504. Commits ------- 4c6a9d2 Proposed a new "best practice" for parameter naming
2 parents cc3874f + 4c6a9d2 commit feaf346

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

best_practices/configuration.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,31 @@ whereas they cannot access the container parameters:
153153
The only notable disadvantage of using constants for this kind of configuration
154154
values is that you cannot redefine them easily in your tests.
155155

156+
Parameter Naming
157+
----------------
158+
159+
.. best-practice::
160+
161+
The name of your configuration parameters should be as short as possible and
162+
should include a common prefix for the entire application.
163+
164+
Using ``app.`` as the prefix of your parameters is a common practice to avoid
165+
collisions with Symfony and third-party bundles/libraries parameters. Then, use
166+
just one or two words to describe the purpose of the parameter:
167+
168+
.. code-block:: yaml
169+
170+
# app/config/config.yml
171+
parameters:
172+
# don't do this: 'dir' is too generic and it doesn't convey any meaning
173+
app.dir: '...'
174+
# do this: short but easy to understand names
175+
app.contents_dir: '...'
176+
# it's OK to use dots, underscores, dashes or nothing, but always
177+
# be consistent and use the same format for all the parameters
178+
app.dir.contents: '...'
179+
app.contents-dir: '...'
180+
156181
Semantic Configuration: Don't Do It
157182
-----------------------------------
158183

0 commit comments

Comments
 (0)