8000 Proposing that we make the service names *just* a little bit longer · symfony/symfony-docs@b1ceb88 · GitHub
[go: up one dir, main page]

Skip to content

Commit b1ceb88

Browse files
committed
Proposing that we make the service names *just* a little bit longer
1 parent 21afb4c commit b1ceb88

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

best_practices/business-logic.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Next, define a new service for that class.
8181
# app/config/services.yml
8282
services:
8383
# keep your service names short
84-
slugger:
84+
app.slugger:
8585
class: AppBundle\Utils\Slugger
8686
8787
Traditionally, the naming convention for a service involved following the
@@ -92,7 +92,8 @@ your code will be easier to read and use.
9292
.. best-practice::
9393

9494
The name of your application's services should be as short as possible,
95-
ideally just one simple word.
95+
but unique enough that you can search your project for the service if
96+
you ever need to.
9697

9798
Now you can use the custom slugger in any controller class, such as the
9899
``AdminController``:
@@ -104,7 +105,7 @@ Now you can use the custom slugger in any controller class, such as the
104105
// ...
105106
106107
if ($form->isSubmitted() && $form->isValid()) {
107-
$slug = $this->get('slugger')->slugify($post->getTitle());
108+
$slug = $this->get('app.slugger')->slugify($post->getTitle());
108109
$post->setSlug($slug);
109110
110111
// ...
@@ -143,7 +144,7 @@ the class namespace as a parameter:
143144
slugger.class: AppBundle\Utils\Slugger
144145
145146
services:
146-
slugger:
147+
app.slugger:
147148
class: "%slugger.class%"
148149
149150
This practice is cumbersome and completely unnecessary for your own services:

0 commit comments

Comments
 (0)
0