Skip to content

Commit

Permalink
feature #4463 [BestPractices] Proposing that we make the service name…
Browse files Browse the repository at this point in the history
…s *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
  • Loading branch information
weaverryan committed Nov 20, 2014
2 parents 21afb4c + b1ceb88 commit 0a21446
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions best_practices/business-logic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Next, define a new service for that class.
# app/config/services.yml
services:
# keep your service names short
slugger:
app.slugger:
class: AppBundle\Utils\Slugger
Traditionally, the naming convention for a service involved following the
Expand All @@ -92,7 +92,8 @@ your code will be easier to read and use.
.. best-practice::

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

Now you can use the custom slugger in any controller class, such as the
``AdminController``:
Expand All @@ -104,7 +105,7 @@ Now you can use the custom slugger in any controller class, such as the
// ...
if ($form->isSubmitted() && $form->isValid()) {
$slug = $this->get('slugger')->slugify($post->getTitle());
$slug = $this->get('app.slugger')->slugify($post->getTitle());
$post->setSlug($slug);
// ...
Expand Down Expand Up @@ -143,7 +144,7 @@ the class namespace as a parameter:
slugger.class: AppBundle\Utils\Slugger
services:
slugger:
app.slugger:
class: "%slugger.class%"
This practice is cumbersome and completely unnecessary for your own services:
Expand Down

0 comments on commit 0a21446

Please sign in to comment.