`.
-
-But, this change will break our app! The old service ids (e.g. ``app.github_notifier``)
-no longer exist. The simplest way to fix this is to find all your old service ids
-and update them to the new class id: ``app.github_notifier`` to ``App\Service\GitHubNotifier``.
-
-In large projects, there's a better way: create legacy aliases that map the old id
-to the new id. Create a new ``legacy_aliases.yaml`` file:
-
-.. code-block:: yaml
-
- # config/legacy_aliases.yaml
- services:
- _defaults:
- public: true
- # aliases so that the old service ids can still be accessed
- # remove these if/when you are not fetching these directly
- # from the container via $container->get()
- app.github_notifier: '@App\Service\GitHubNotifier'
- markdown_transformer: '@App\Service\MarkdownTransformer'
-
-Then import this at the top of ``services.yaml``:
-
-.. code-block:: diff
-
- # config/services.yaml
- + imports:
- + - { resource: legacy_aliases.yaml }
-
- # ...
-
-That's it! The old service ids still work. Later, (see the cleanup step below), you
-can remove these from your app.
-
-Step 3) Make the Services Private
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Now you're ready to default all services to be private:
-
-.. code-block:: diff
-
- # config/services.yaml
- # ...
-
- services:
- _defaults:
- autowire: true
- autoconfigure: true
- + public: false
-
-Thanks to this, any services created in this file cannot be fetched directly from
-the container. But, since the old service id's are aliases in a separate file (``legacy_aliases.yaml``),
-these *are* still public. This makes sure the app keeps working.
-
-If you did *not* change the id of some of your services (because there are multiple
-instances of the same class), you may need to make those public:
-
-.. code-block:: diff
-
- # config/services.yaml
- # ...
-
- services:
- # ...
-
- app.api_client_github:
- # ...
-
- + # remove this if/when you are not fetching this
- + # directly from the container via $container->get()
- + public: true
-
- app.api_client_sl_connect:
- # ...
- + public: true
-
-This is to guarantee that the application doesn't break. If you're not fetching
-these services directly from the container, this isn't needed. In a minute, you'll
-clean that up.
-
-Step 4) Auto-registering Services
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-You're now ready to automatically register all services in ``src/``
-(and/or any other directory/bundle you have):
-
-.. code-block:: diff
-
- # config/services.yaml
-
- services:
- _defaults:
- # ...
-
- + App\:
- + resource: '../src/*'
- + exclude: '../src/{Entity,Migrations,Tests}'
- +
- + App\Controller\:
- + resource: '../src/Controller'
- + tags: ['controller.service_arguments']
-
- # ...
-
-That's it! Actually, you're already overriding and reconfiguring all the services
-you're using (``App\Service\GitHubNotifier`` and ``App\Service\MarkdownTransformer``).
-But now, you won't need to manually register future services.
-
-Once again, there is one extra complication if you have multiple services of the
-same class:
-
-.. code-block:: diff
-
- # config/services.yaml
-
- services:
- # ...
-
- + # alias ApiClient to one of our services below
- + # app.api_client_github will be used to autowire ApiClient type-hints
- + App\Service\ApiClient: '@app.api_client_github'
-
- app.api_client_github:
- # ...
- app.api_client_sl_connect:
- # ...
-
-This guarantees that if you try to autowire an ``ApiClient`` instance, the ``app.api_client_github``
-will be used. If you *don't* have this, the auto-registration feature will try to
-register a third ``ApiClient`` service and use that for autowiring (which will fail,
-because the class has a non-autowireable argument).
-
-.. _step-5:
-
-Step 5) Cleanup!
-~~~~~~~~~~~~~~~~
-
-To make sure your application didn't break, you did some extra work. Now it's time
-to clean things up! First, update your application to *not* use the old service id's (the
-ones in ``legacy_aliases.yaml``). This means updating any service arguments (e.g.
-``@app.github_notifier`` to ``@App\Service\GitHubNotifier``) and updating your
-code to not fetch this service directly from the container. For example:
-
-.. code-block:: diff
-
- - public function index()
- + public function index(GitHubNotifier $gitHubNotifier, MarkdownTransformer $markdownTransformer)
- {
- - // the old way of fetching services
- - $githubNotifier = $this->container->get('app.github_notifier');
- - $markdownTransformer = $this->container->get('markdown_transformer');
-
- // ...
- }
-
-As soon as you do this, you can delete ``legacy_aliases.yaml`` and remove its import.
-You should do the same thing for any services that you made public, like
-``app.api_client_github`` and ``app.api_client_sl_connect``. Once you're not fetching
-these directly from the container, you can remove the ``public: true`` flag:
-
-.. code-block:: diff
-
- # config/services.yaml
- services:
- # ...
-
- app.api_client_github:
- # ...
- - public: true
-
- app.api_client_sl_connect:
- # ...
- - public: true
-
-Finally, you can optionally remove any services from ``services.yaml`` whose arguments
-can be autowired. The final configuration looks like this:
-
-.. code-block:: yaml
-
- services:
- _defaults:
- autowire: true
- autoconfigure: true
- public: false
-
- App\:
- resource: '../src/*'
- exclude: '../src/{Entity,Migrations,Tests}'
-
- App\Controller\:
- resource: '../src/Controller'
- tags: ['controller.service_arguments']
-
- App\Service\GitHubNotifier:
- # this could be deleted, or I can keep being explicit
- arguments:
- - '@app.api_client_github'
-
- # alias ApiClient to one of our services below
- # app.api_client_github will be used to autowire ApiClient type-hints
- App\Service\ApiClient: '@app.api_client_github'
-
- # keep these ids because there are multiple instances per class
- app.api_client_github:
- class: App\Service\ApiClient
- arguments:
- - 'https://api.github.com'
-
- app.api_client_sl_connect:
- class: App\Service\ApiClient
- arguments:
- - 'https://connect.symfony.com/api'
-
-You can now take advantage of the new features going forward.
-
-.. _`FrameworkExtension for 3.3.0`: https://github.com/symfony/symfony/blob/7938fdeceb03cc1df277a249cf3da70f0b50eb98/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L247-L284
diff --git a/setup/flex.rst b/setup/flex.rst
index df1bf1eaa14..eaba102d073 100644
--- a/setup/flex.rst
+++ b/setup/flex.rst
@@ -100,7 +100,7 @@ manual steps:
located at ``config/services.yaml``. Copy the contents of the
`default services.yaml file`_ and then add your own service configuration.
Later you can revisit this file because thanks to Symfony's
- :doc:`autowiring feature ` you can remove
+ :doc:`autowiring feature ` you can remove
most of the service configuration.
.. note::
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy