Skip to content

Commit 0a21446

Browse files
committed
feature #4463 [BestPractices] Proposing that we make the service names *just* a little bit longer (weaverryan)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #4463). Discussion ---------- [BestPractices] Proposing that we make the service names *just* a little bit longer | Q | A | --- | --- | Doc fix? | no | New docs? | no | Applies to | 2.3+ | Fixed tickets | - Hi guys! This is a very minor proposed change for the best practices, which I would like to consider. The original best practice was because we don't want people to blindly follow the 3rd party service naming that's quite long. In your own app, they just need to be unique within yourself. But personally, I *do* use things like `app.slugger`, because I like to be able to grep my codebase for a service and reliably find it. Thanks! Commits ------- b1ceb88 Proposing that we make the service names *just* a little bit longer
2 parents 21afb4c + b1ceb88 commit 0a21446

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

best_practices/business-logic.rst

+5-4
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)