@@ -8,19 +8,19 @@ without sacrificing predictability, which is very important! Another goal is to
8
8
controllers and services behave more consistently. In Symfony 3.3, controllers *are *
9
9
services by default.
10
10
11
- The documentation has already been updated to assume you have these new features enabled.
12
- If you're an existing Symfony user and want to understand the "what" and "why" behind
13
- these changes, this chapter is for you!
11
+ The documentation has already been updated to assume you have these new features
12
+ enabled. If you're an existing Symfony user and want to understand the "what"
13
+ and "why" behind these changes, this article is for you!
14
14
15
- All Changes are Opt-In
16
- ----------------------
15
+ All Changes are Optional
16
+ ------------------------
17
17
18
18
Most importantly, **you can upgrade to Symfony 3.3 today without making any changes to your app **.
19
19
Symfony has a strict :doc: `backwards compatibility promise </contributing/code/bc >`,
20
20
which means it's always safe to upgrade across minor versions.
21
21
22
- All of the new features are **opt-in **: you need to actually change your configuration
23
- files to use them.
22
+ All of the new features are **optional **: they are not enabled by default, so you
23
+ need to actually change your configuration files to use them.
24
24
25
25
The new Default services.yml File
26
26
---------------------------------
@@ -151,7 +151,7 @@ thanks to the following config:
151
151
// services cannot be automatically loaded with PHP configuration
152
152
// you need to define your services one-by-one
153
153
154
- This means that every class in ``src/AppBundle `` is *available * to be used as a
154
+ This means that every class in ``src/AppBundle/ `` is *available * to be used as a
155
155
service. And thanks to the ``_defaults `` section at the top of the file, all of
156
156
these services are **autowired ** and **private ** (i.e. ``public: false ``).
157
157
@@ -166,7 +166,7 @@ to determine most arguments automatically. But, you can always override the serv
166
166
and :ref: `manually configure arguments <services-manually-wire-args >` or anything
167
167
else special about your service.
168
168
169
- But wait, if I have some model (non-service) classes in my ``src/AppBundle ``
169
+ But wait, if I have some model (non-service) classes in my ``src/AppBundle/ ``
170
170
directory, doesn't this mean that *they * will also be registered as services?
171
171
Isn't that a problem?
172
172
@@ -230,12 +230,12 @@ To pass the ``InvoiceGenerator`` as an argument to ``InvoiceMailer``, you needed
230
230
to specify the service's *id * as an argument: ``app.invoice_generator ``. Service
231
231
id's were the main way that you configured things.
232
232
233
- But in Symfony 3.3, thanks to autowiring, all you need to do is type-hint the argument
234
- with ``InvoiceGenerator ``::
233
+ But in Symfony 3.3, thanks to autowiring, all you need to do is type-hint the
234
+ argument with ``InvoiceGenerator ``::
235
235
236
236
// src/AppBundle/Service/InvoiceMailer.php
237
237
// ...
238
-
238
+
239
239
class InvoiceMailer
240
240
{
241
241
private $generator;
@@ -288,7 +288,7 @@ was designed with that in mind. Specifically:
288
288
a service whose id matches the type-hint exactly. It does *not * scan all services
289
289
looking for objects that have that class/interface (actually, it *does * do this
290
290
in Symfony 3.3, but has been deprecated. If you rely on this, you will see a clear
291
- deprecation warning).
291
+ deprecation warning).
292
292
293
293
Autowiring aims to *automate * configuration without magic.
294
294
@@ -387,7 +387,7 @@ create the class::
387
387
388
388
// src/AppBundle/EventSubscriber/SetHeaderSusbcriber.php
389
389
// ...
390
-
390
+
391
391
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
392
392
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
393
393
use Symfony\Component\HttpKernel\KernelEvents;
@@ -398,7 +398,7 @@ create the class::
398
398
{
399
399
$event->getResponse()->headers->set('X-SYMFONY-3.3', 'Less config');
400
400
}
401
-
401
+
402
402
public static function getSubscribedEvents()
403
403
{
404
404
return [
@@ -499,8 +499,8 @@ Start by adding a ``_defaults`` section with ``autowire`` and ``autoconfigure``.
499
499
# ...
500
500
501
501
This step is easy: you're already *explicitly * configuring all of your services.
502
- So, ``autowire `` does nothing. You're also already tagging your services, so `` autoconfigure ``
503
- also doesn't change any existing services.
502
+ So, ``autowire `` does nothing. You're also already tagging your services, so
503
+ `` autoconfigure `` also doesn't change any existing services.
504
504
505
505
You have not added ``public: false `` yet. That will come in a minute.
506
506
@@ -574,7 +574,7 @@ Now you're ready to default all services to be private:
574
574
575
575
# app/config/services.yml
576
576
# ...
577
-
577
+
578
578
services:
579
579
_defaults:
580
580
autowire: true
@@ -592,7 +592,7 @@ instances of the same class), you may need to make those public:
592
592
593
593
# app/config/services.yml
594
594
# ...
595
-
595
+
596
596
services:
597
597
# ...
598
598
@@ -602,7 +602,7 @@ instances of the same class), you may need to make those public:
602
602
+ # remove this if/when you are not fetching this
603
603
+ # directly from the container via $container->get()
604
604
+ public: true
605
-
605
+
606
606
app.api_client_sl_connect:
607
607
# ...
608
608
+ public: true
@@ -614,8 +614,8 @@ clean that up.
614
614
Step 4) Auto-registering Services
615
615
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
616
616
617
- You're now ready to automatically register all services in ``src/AppBundle `` (and/or
618
- any other directory/bundle you have):
617
+ You're now ready to automatically register all services in ``src/AppBundle/ ``
618
+ (and/or any other directory/bundle you have):
619
619
620
620
.. code-block :: diff
621
621
@@ -697,7 +697,7 @@ these directly from the container, you can remove the ``public: true`` flag:
697
697
app.api_client_github:
698
698
# ...
699
699
- public: true
700
-
700
+
701
701
app.api_client_sl_connect:
702
702
# ...
703
703
- public: true
0 commit comments