|
1 | 1 | services: |
2 | | - # First we define some basic services to make these utilities available in |
3 | | - # the entire application |
4 | | - slugger: |
5 | | - class: AppBundle\Utils\Slugger |
6 | | - |
7 | | - markdown: |
8 | | - class: AppBundle\Utils\Markdown |
9 | | - |
10 | | - # These are the Twig extensions that create new filters and functions for |
11 | | - # using them in the templates |
12 | | - app.twig.app_extension: |
13 | | - public: false |
14 | | - class: AppBundle\Twig\AppExtension |
15 | | - arguments: ['@markdown', '%app_locales%'] |
16 | | - tags: |
17 | | - - { name: twig.extension } |
18 | | - |
19 | | - app.twig.intl_extension: |
20 | | - public: false |
21 | | - class: Twig_Extensions_Extension_Intl |
22 | | - tags: |
23 | | - - { name: twig.extension } |
24 | | - |
25 | | - # Defining a form type as a service is only required when the form type |
26 | | - # needs to use some other services, such as the entity manager. |
27 | | - # See https://symfony.com/doc/current/best_practices/forms.html |
28 | | - app.form.type.tagsinput: |
29 | | - class: AppBundle\Form\Type\TagsInputType |
30 | | - arguments: ['@doctrine.orm.entity_manager'] |
31 | | - tags: |
32 | | - - { name: form.type } |
33 | | - |
34 | | - # Event Listeners are classes that listen to one or more specific events. |
35 | | - # Those events are defined in the tags added to the service definition. |
36 | | - # See https://symfony.com/doc/current/event_dispatcher.html#creating-an-event-listener |
37 | | - app.redirect_to_preferred_locale_listener: |
38 | | - class: AppBundle\EventListener\RedirectToPreferredLocaleListener |
39 | | - arguments: ['@router', '%app_locales%', '%locale%'] |
40 | | - tags: |
41 | | - - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest } |
42 | | - |
43 | | - app.comment_notification: |
44 | | - class: AppBundle\EventListener\CommentNotificationListener |
45 | | - arguments: ['@mailer', '@router', '@translator', '%app.notifications.email_sender%'] |
46 | | - # The "method" attribute of this tag is optional and defaults to "on + camelCasedEventName" |
47 | | - # If the event is "comment.created" the method executed by default is "onCommentCreated()". |
48 | | - tags: |
49 | | - - { name: kernel.event_listener, event: comment.created, method: onCommentCreated } |
50 | | - |
51 | | - # Event subscribers are similar to event listeners but they don't need service tags. |
52 | | - # Instead, the PHP class of the event subscriber includes a method that returns |
53 | | - # the list of events listened by that class. |
54 | | - # See https://symfony.com/doc/current/event_dispatcher.html#creating-an-event-subscriber |
55 | | - app.requirements_subscriber: |
56 | | - class: AppBundle\EventListener\CheckRequirementsSubscriber |
57 | | - arguments: ['@doctrine.orm.entity_manager'] |
58 | | - tags: |
59 | | - - { name: kernel.event_subscriber } |
60 | | - |
61 | | - # To inject the voter into the security layer, you must declare it as a service and tag it with security.voter. |
62 | | - # See https://symfony.com/doc/current/security/voters.html#configuring-the-voter |
63 | | - app.post_voter: |
64 | | - class: AppBundle\Security\PostVoter |
| 2 | + # default configuration for services in *this* file |
| 3 | + _defaults: |
| 4 | + # automatically injects dependencies in your services |
| 5 | + autowire: true |
| 6 | + # automatically registers your services as commands, event subscribers, etc. |
| 7 | + autoconfigure: true |
| 8 | + # this means you cannot fetch services directly from the container via $container->get() |
| 9 | + # if you need to do this, you can override this setting on individual services |
65 | 10 | public: false |
66 | | - tags: |
67 | | - - { name: security.voter } |
68 | 11 |
|
69 | | - # Uncomment the following lines to define a service for the Post Doctrine repository. |
70 | | - # It's not mandatory to create these services, but if you use repositories a lot, |
71 | | - # these services simplify your code: |
72 | | - # |
73 | | - # app.post_repository: |
74 | | - # class: Doctrine\ORM\EntityRepository |
75 | | - # factory: ['@doctrine.orm.entity_manager', getRepository] |
76 | | - # arguments: [AppBundle\Entity\Post] |
77 | | - # |
78 | | - # // traditional code inside a controller |
79 | | - # $entityManager = $this->getDoctrine()->getManager(); |
80 | | - # $posts = $entityManager->getRepository('AppBundle:Post')->findAll(); |
81 | | - # |
82 | | - # // same code using repository services |
83 | | - # $posts = $this->get('app.post_repository')->findAll(); |
| 12 | + # makes classes in src/AppBundle available to be used as services |
| 13 | + # this creates a service per class whose id is the fully-qualified class name |
| 14 | + AppBundle\: |
| 15 | + resource: '../../src/AppBundle/*' |
| 16 | + # you can exclude directories or files |
| 17 | + # but if a service is unused, it's removed anyway |
| 18 | + exclude: '../../src/AppBundle/{Controller,Entity,Repository}' |
| 19 | + |
| 20 | + # controllers are imported separately to make sure they're public |
| 21 | + # and have a tag that allows actions to type-hint services |
| 22 | + AppBundle\Controller\: |
| 23 | + resource: '../../src/AppBundle/Controller' |
| 24 | + public: true |
| 25 | + tags: ['controller.service_arguments'] |
| 26 | + |
| 27 | + # Autowiring can't guess the constructor arguments that are not type-hinted with |
| 28 | + # classes (e.g. container parameters) so you must define those arguments explicitly |
| 29 | + AppBundle\Command\ListUsersCommand: |
| 30 | + arguments: |
| 31 | + $emailSender: '%app.notifications.email_sender%' |
| 32 | + |
| 33 | + AppBundle\Twig\AppExtension: |
| 34 | + arguments: |
| 35 | + $locales: '%app_locales%' |
| 36 | + |
| 37 | + AppBundle\EventListener\CommentNotificationSubscriber: |
| 38 | + arguments: |
| 39 | + $sender: '%app.notifications.email_sender%' |
| 40 | + |
| 41 | + AppBundle\EventListener\RedirectToPreferredLocaleSubscriber: |
| 42 | + arguments: |
| 43 | + $locales: '%app_locales%' |
| 44 | + $defaultLocale: '%locale%' |
| 45 | + |
| 46 | + # needed for the localizeddate Twig filter |
| 47 | + Twig\Extensions\IntlExtension: ~ |
0 commit comments