Skip to content

Commit ebd23b5

Browse files
committed
feature #8580 Fix 3.3 DI changes with Symfony Flex structure (yceruto)
This PR was merged into the master branch. Discussion ---------- Fix 3.3 DI changes with Symfony Flex structure Commits ------- 9c5f7cc Fix 3.3 DI changes
2 parents 69036a3 + 9c5f7cc commit ebd23b5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

service_container/3.3-di-changes.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Symfony Standard Edition:
4646
# if you need to do this, you can override this setting on individual services
4747
public: false
4848
49-
# makes classes in src/AppBundle available to be used as services
49+
# makes classes in src/ available to be used as services
5050
# this creates a service per class whose id is the fully-qualified class name
5151
App\:
5252
resource: '../../src/*'
@@ -136,7 +136,7 @@ thanks to the following config:
136136
services:
137137
# ...
138138
139-
# makes classes in src/AppBundle available to be used as services
139+
# makes classes in src/ available to be used as services
140140
# this creates a service per class whose id is the fully-qualified class name
141141
App\:
142142
resource: '../../src/*'
@@ -180,7 +180,7 @@ This means that every class in ``src/`` is *available* to be used as a
180180
service. And thanks to the ``_defaults`` section at the top of the file, all of
181181
these services are **autowired** and **private** (i.e. ``public: false``).
182182

183-
The service ids are equal to the class name (e.g. ``AppBundle\Service\InvoiceGenerator``).
183+
The service ids are equal to the class name (e.g. ``App\Service\InvoiceGenerator``).
184184
And that's another change you'll notice in Symfony 3.3: we recommend that you use
185185
the class name as your service id, unless you have :ref:`multiple services for the same class <services-explicitly-configure-wire-services>`.
186186

@@ -289,8 +289,8 @@ argument with ``InvoiceGenerator``::
289289

290290
That's it! Both services are :ref:`automatically registered <service-33-changes-automatic-registration>`
291291
and set to autowire. Without *any* configuration, the container knows to pass the
292-
auto-registered ``AppBundle\Service\InvoiceGenerator`` as the first argument. As
293-
you can see, the *type* of the class - ``AppBundle\Service\InvoiceGenerator`` - is
292+
auto-registered ``App\Service\InvoiceGenerator`` as the first argument. As
293+
you can see, the *type* of the class - ``App\Service\InvoiceGenerator`` - is
294294
what's most important, not the id. You request an *instance* of a specific type and
295295
the container automatically passes you the correct service.
296296

@@ -379,7 +379,7 @@ The third big change is that, in a new Symfony 3.3 project, your controllers are
379379
But, you might not even notice this. First, your controllers *can* still extend
380380
the same base ``Controller`` class or a new :ref:`AbstractController <controller-abstract-versus-controller>`.
381381
This means you have access to all of the same shortcuts as before. Additionally,
382-
the ``@Route`` annotation and ``_controller`` syntax (e.g. ``AppBundle:Default:homepage``)
382+
the ``@Route`` annotation and ``_controller`` syntax (e.g. ``App:Default:homepage``)
383383
used in routing will automatically use your controller as a service (as long as its
384384
service id matches its class name, which it *does* in this case). See :doc:`/controller/service`
385385
for more details. You can even create :ref:`invokable controllers <controller-service-invoke>`
@@ -631,7 +631,7 @@ Start by updating the service ids to class names:
631631

632632
But, this change will break our app! The old service ids (e.g. ``app.github_notifier``)
633633
no longer exist. The simplest way to fix this is to find all your old service ids
634-
and update them to the new class id: ``app.github_notifier`` to ``AppBundle\Service\GitHubNotifier``.
634+
and update them to the new class id: ``app.github_notifier`` to ``App\Service\GitHubNotifier``.
635635

636636
In large projects, there's a better way: create legacy aliases that map the old id
637637
to the new id. Create a new ``legacy_aliases.yml`` file:
@@ -730,7 +730,7 @@ You're now ready to automatically register all services in ``src/``
730730
# ...
731731
732732
That's it! Actually, you're already overriding and reconfiguring all the services
733-
you're using (``AppBundle\Service\GitHubNotifier`` and ``AppBundle\Service\MarkdownTransformer``).
733+
you're using (``App\Service\GitHubNotifier`` and ``App\Service\MarkdownTransformer``).
734734
But now, you won't need to manually register future services.
735735

736736
Once again, there is one extra complication if you have multiple services of the
@@ -763,7 +763,7 @@ Step 5) Cleanup!
763763
To make sure your application didn't break, you did some extra work. Now it's time
764764
to clean things up! First, update your application to *not* use the old service id's (the
765765
ones in ``legacy_aliases.yml``). This means updating any service arguments (e.g.
766-
``@app.github_notifier`` to ``@AppBundle\Service\GitHubNotifier``) and updating your
766+
``@app.github_notifier`` to ``@App\Service\GitHubNotifier``) and updating your
767767
code to not fetch this service directly from the container. For example:
768768

769769
.. code-block:: diff

0 commit comments

Comments
 (0)