Skip to content

[BestPractices] Proposing that we make the service names *just* a little bit longer #4463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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