@@ -492,9 +492,9 @@ Start by adding a ``_defaults`` section with ``autowire`` and ``autoconfigure``.
492492
493493 # app/config/services.yml
494494 services:
495- + _defaults:
496- + autowire: true
497- + autoconfigure: true
495+ + _defaults:
496+ + autowire: true
497+ + autoconfigure: true
498498
499499 # ...
500500
@@ -519,15 +519,15 @@ Start by updating the service ids to class names:
519519 services:
520520 # ...
521521
522- - app.github_notifier:
523- - class: AppBundle\Service\GitHubNotifier
524- + AppBundle\Service\GitHubNotifier:
522+ - app.github_notifier:
523+ - class: AppBundle\Service\GitHubNotifier
524+ + AppBundle\Service\GitHubNotifier:
525525 arguments:
526526 - '@app.api_client_github'
527527
528- - markdown_transformer:
529- - class: AppBundle\Service\MarkdownTransformer
530- + AppBundle\Service\MarkdownTransformer: ~
528+ - markdown_transformer:
529+ - class: AppBundle\Service\MarkdownTransformer
530+ + AppBundle\Service\MarkdownTransformer: ~
531531
532532 # keep these ids because there are multiple instances per class
533533 app.api_client_github:
@@ -557,8 +557,8 @@ Then import this at the top of ``services.yml``:
557557.. code-block :: diff
558558
559559 # app/config/services.yml
560- +imports:
561- + - { resource: legacy_aliases.yml }
560+ + imports:
561+ + - { resource: legacy_aliases.yml }
562562
563563 # ...
564564
@@ -579,7 +579,7 @@ Now you're ready to default all services to be private:
579579 _defaults:
580580 autowire: true
581581 autoconfigure: true
582- + public: false
582+ + public: false
583583
584584 Thanks to this, any services created in this file cannot be fetched directly from
585585the container. But, since the old service id's are aliases in a separate file (``legacy_aliases.yml ``),
@@ -596,16 +596,16 @@ instances of the same class), you may need to make those public:
596596 services:
597597 # ...
598598
599- app.api_client_github:
600- # ...
599+ app.api_client_github:
600+ # ...
601601
602- + # remove this if/when you are not fetching this
603- + # directly from the container via $container->get()
604- + public: true
602+ + # remove this if/when you are not fetching this
603+ + # directly from the container via $container->get()
604+ + public: true
605605
606- app.api_client_sl_connect:
607- # ...
608- + public: true
606+ app.api_client_sl_connect:
607+ # ...
608+ + public: true
609609
610610 This is to guarantee that the application doesn't break. If you're not fetching
611611these services directly from the container, this isn't needed. In a minute, you'll
@@ -625,14 +625,14 @@ You're now ready to automatically register all services in ``src/AppBundle/``
625625 _defaults:
626626 # ...
627627
628- + AppBundle\:
629- + resource: '../../src/AppBundle/*'
630- + exclude: '../../src/AppBundle/{Entity,Repository}'
631- +
632- + AppBundle\Controller\:
633- + resource: '../../src/AppBundle/Controller'
634- + public: true
635- + tags: ['controller.service_arguments']
628+ + AppBundle\:
629+ + resource: '../../src/AppBundle/*'
630+ + exclude: '../../src/AppBundle/{Entity,Repository}'
631+ +
632+ + AppBundle\Controller\:
633+ + resource: '../../src/AppBundle/Controller'
634+ + public: true
635+ + tags: ['controller.service_arguments']
636636
637637 # ...
638638
@@ -650,14 +650,14 @@ same class:
650650 services:
651651 # ...
652652
653- + # alias ApiClient to one of our services below
654- + # app.api_client_github will be used to autowire ApiClient type-hints
655- + AppBundle\Service\ApiClient: '@app.api_client_github'
653+ + # alias ApiClient to one of our services below
654+ + # app.api_client_github will be used to autowire ApiClient type-hints
655+ + AppBundle\Service\ApiClient: '@app.api_client_github'
656656
657- app.api_client_github:
658- # ...
659- app.api_client_sl_connect:
660- # ...
657+ app.api_client_github:
658+ # ...
659+ app.api_client_sl_connect:
660+ # ...
661661
662662 This guarantees that if you try to autowire an ``ApiClient `` instance, the ``app.api_client_github ``
663663will be used. If you *don't * have this, the auto-registration feature will try to
@@ -671,17 +671,19 @@ To make sure your application didn't break, you did some extra work. Now it's ti
671671to clean things up! First, update your application to *not * use the old service id's (the
672672ones in ``legacy_aliases.yml ``). This means updating any service arguments (e.g.
673673``@app.github_notifier `` to ``@AppBundle\Service\GitHubNotifier ``) and updating your
674- code to not fetch this service directly from the container. For example::
674+ code to not fetch this service directly from the container. For example:
675675
676- - public function indexAction()
677- + public function indexAction(GitHubNotifier $gitHubNotifier, MarkdownTransformer $markdownTransformer)
678- {
679- - // the old way of fetching services
680- - $githubNotifier = $this->container->get('app.github_notifier');
681- - $markdownTransformer = $this->container->get('markdown_transformer');
676+ .. code-block :: diff
677+
678+ - public function indexAction()
679+ + public function indexAction(GitHubNotifier $gitHubNotifier, MarkdownTransformer $markdownTransformer)
680+ {
681+ - // the old way of fetching services
682+ - $githubNotifier = $this->container->get('app.github_notifier');
683+ - $markdownTransformer = $this->container->get('markdown_transformer');
682684
683685 // ...
684- }
686+ }
685687
686688 As soon as you do this, you can delete ``legacy_aliases.yml `` and remove its import.
687689You should do the same thing for any services that you made public, like
@@ -694,13 +696,13 @@ these directly from the container, you can remove the ``public: true`` flag:
694696 services:
695697 # ...
696698
697- app.api_client_github:
698- # ...
699- - public: true
699+ app.api_client_github:
700+ # ...
701+ - public: true
700702
701- app.api_client_sl_connect:
702- # ...
703- - public: true
703+ app.api_client_sl_connect:
704+ # ...
705+ - public: true
704706
705707 Finally, you can optionally remove any services from ``services.yml `` whose arguments
706708can be autowired. The final configuration looks like this:
0 commit comments