@@ -81,8 +81,8 @@ Configuration
81
81
Use Environment Variables for Infrastructure Configuration
82
82
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83
83
84
- The values of these options change from one machine to another (e.g. from your
85
- development machine to the production server) but they don't modify the
84
+ The values of these options change from one machine to another (e.g., from your
85
+ development machine to the production server), but they don't modify the
86
86
application behavior.
87
87
88
88
:ref: `Use env vars in your project <config-env-vars >` to define these options
@@ -93,7 +93,7 @@ and create multiple ``.env`` files to :ref:`configure env vars per environment <
93
93
Use Secrets for Sensitive Information
94
94
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95
95
96
- When your application has sensitive configuration - like an API key - you should
96
+ When your application has sensitive configuration, like an API key, you should
97
97
store those securely via :doc: `Symfony’s secrets management system </configuration/secrets >`.
98
98
99
99
Use Parameters for Application Configuration
@@ -119,7 +119,7 @@ Then, use just one or two words to describe the purpose of the parameter:
119
119
120
120
# config/services.yaml
121
121
parameters :
122
- # don't do this: 'dir' is too generic and it doesn't convey any meaning
122
+ # don't do this: 'dir' is too generic, and it doesn't convey any meaning
123
123
app.dir : ' ...'
124
124
# do this: short but easy to understand names
125
125
app.contents_dir : ' ...'
@@ -164,7 +164,7 @@ InvoiceBundle, etc. However, a bundle is meant to be something that can be
164
164
reused as a stand-alone piece of software.
165
165
166
166
If you need to reuse some feature in your projects, create a bundle for it (in a
167
- private repository, to not make it publicly available). For the rest of your
167
+ private repository, do not make it publicly available). For the rest of your
168
168
application code, use PHP namespaces to organize code instead of bundles.
169
169
170
170
Use Autowiring to Automate the Configuration of Application Services
@@ -186,14 +186,14 @@ Services Should be Private Whenever Possible
186
186
those services via ``$container->get() ``. Instead, you will need to use proper
187
187
dependency injection.
188
188
189
- Use the YAML Format to Configure your Own Services
189
+ Use the YAML Format to Configure your own Services
190
190
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191
191
192
192
If you use the :ref: `default services.yaml configuration <service-container-services-load-example >`,
193
193
most services will be configured automatically. However, in some edge cases
194
194
you'll need to configure services (or parts of them) manually.
195
195
196
- YAML is the format recommended to configure services because it's friendly to
196
+ YAML is the format recommended configuring services because it's friendly to
197
197
newcomers and concise, but Symfony also supports XML and PHP configuration.
198
198
199
199
Use Attributes to Define the Doctrine Entity Mapping
@@ -228,13 +228,13 @@ important parts of your application.
228
228
229
229
.. _best-practice-controller-annotations :
230
230
231
- Use Attributes or Annotations to Configure Routing, Caching and Security
231
+ Use Attributes or Annotations to Configure Routing, Caching, and Security
232
232
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
233
233
234
- Using attributes or annotations for routing, caching and security simplifies
234
+ Using attributes or annotations for routing, caching, and security simplifies
235
235
configuration. You don't need to browse several files created with different
236
- formats (YAML, XML, PHP): all the configuration is just where you need it and
237
- it only uses one format.
236
+ formats (YAML, XML, PHP): all the configuration is just where you require it,
237
+ and it only uses one format.
238
238
239
239
Use Dependency Injection to Get Services
240
240
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -256,15 +256,15 @@ controller. It will also show a 404 page if no entity can be found.
256
256
257
257
If the logic to get an entity from a route variable is more complex, instead of
258
258
configuring the EntityValueResolver, it's better to make the Doctrine query
259
- inside the controller (e.g. by calling to a :doc: `Doctrine repository method </doctrine >`).
259
+ inside the controller (e.g., by calling to a :doc: `Doctrine repository method </doctrine >`).
260
260
261
261
Templates
262
262
---------
263
263
264
264
Use Snake Case for Template Names and Variables
265
265
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
266
266
267
- Use lowercase snake_case for template names, directories and variables (e.g.
267
+ Use lowercase snake_case for template names, directories, and variables (e.g.,
268
268
``user_profile `` instead of ``userProfile `` and ``product/edit_form.html.twig ``
269
269
instead of ``Product/EditForm.html.twig ``).
270
270
@@ -273,7 +273,7 @@ Prefix Template Fragments with an Underscore
273
273
274
274
Template fragments, also called *"partial templates" *, allow to
275
275
:ref: `reuse template contents <templates-reuse-contents >`. Prefix their names
276
- with an underscore to better differentiate them from complete templates (e.g.
276
+ with an underscore to better differentiate them from complete templates (e.g.,
277
277
``_user_metadata.html.twig `` or ``_caution_message.html.twig ``).
278
278
279
279
Forms
@@ -282,7 +282,7 @@ Forms
282
282
Define your Forms as PHP Classes
283
283
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
284
284
285
- Creating :ref: `forms in classes <creating-forms-in-classes >` allows to reuse
285
+ Creating :ref: `forms in classes <creating-forms-in-classes >` allows reusing
286
286
them in different parts of the application. Besides, not creating forms in
287
287
controllers simplifies the code and maintenance of the controllers.
288
288
@@ -294,7 +294,7 @@ button of a form used to both create and edit items should change from "Add new"
294
294
to "Save changes" depending on where it's used.
295
295
296
296
Instead of adding buttons in form classes or the controllers, it's recommended
297
- to add buttons in the templates. This also improves the separation of concerns,
297
+ to add buttons in the templates. This also improves the separation of concerns
298
298
because the button styling (CSS class and other attributes) is defined in the
299
299
template instead of in a PHP class.
300
300
@@ -316,7 +316,7 @@ Use a Single Action to Render and Process the Form
316
316
317
317
:ref: `Rendering forms <rendering-forms >` and :ref: `processing forms <processing-forms >`
318
318
are two of the main tasks when handling forms. Both are too similar (most of the
319
- times , almost identical), so it's much simpler to let a single controller action
319
+ time , almost identical), so it's much simpler to let a single controller action
320
320
handle both.
321
321
322
322
.. _best-practice-internationalization :
@@ -340,8 +340,8 @@ Use Keys for Translations Instead of Content Strings
340
340
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
341
341
342
342
Using keys simplifies the management of the translation files because you can
343
- change the original contents in templates, controllers and services without
344
- having to update all of the translation files.
343
+ change the original contents in templates, controllers, and services without
344
+ having to update all the translation files.
345
345
346
346
Keys should always describe their *purpose * and *not * their location. For
347
347
example, if a form has a field with the label "Username", then a nice key
@@ -354,7 +354,7 @@ Define a Single Firewall
354
354
~~~~~~~~~~~~~~~~~~~~~~~~
355
355
356
356
Unless you have two legitimately different authentication systems and users
357
- (e.g. form login for the main site and a token system for your API only), it's
357
+ (e.g., form login for the main site and a token system for your API only), it's
358
358
recommended to have only one firewall to keep things simple.
359
359
360
360
Additionally, you should use the ``anonymous `` key under your firewall. If you
@@ -381,13 +381,13 @@ Web Assets
381
381
Use Webpack Encore to Process Web Assets
382
382
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
383
383
384
- Web assets are things like CSS, JavaScript and image files that make the
384
+ Web assets are things like CSS, JavaScript, and image files that make the
385
385
frontend of your site look and work great. `Webpack `_ is the leading JavaScript
386
386
module bundler that compiles, transforms and packages assets for usage in a browser.
387
387
388
388
:doc: `Webpack Encore </frontend >` is a JavaScript library that gets rid of most
389
389
of Webpack complexity without hiding any of its features or distorting its usage
390
- and philosophy. It was originally created for Symfony applications, but it works
390
+ and philosophy. It was created for Symfony applications, but it works
391
391
for any application using any technology.
392
392
393
393
Tests
@@ -445,7 +445,7 @@ public URL changes, users won't be able to browse it unless you set up a
445
445
redirection to the new URL.
446
446
447
447
That's why it's recommended to use raw URLs in tests instead of generating them
448
- from routes. Whenever a route changes, tests will fail and you'll know that
448
+ from routes. Whenever a route changes, tests will fail, and you'll know that
449
449
you must set up a redirection.
450
450
451
451
.. _`Symfony Demo` : https://github.com/symfony/demo
0 commit comments