Skip to content

Commit e2d6e01

Browse files
committed
Merge remote-tracking branch 'upstream/3.3' into 3.3
2 parents 6fac6c2 + b3f570e commit e2d6e01

File tree

10 files changed

+123
-37
lines changed

10 files changed

+123
-37
lines changed

bundles/extension.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,9 @@ read more about it, see the ":doc:`/bundles/configuration`" article.
129129
Adding Classes to Compile
130130
-------------------------
131131

132-
.. note::
133-
134-
The ``addClassesToCompile()`` method was deprecated in Symfony 3.3, and will
135-
be removed in Symfony 4.0. If you want to use this method and be compatible
136-
with Symfony 4.0, check to see if the method exists before calling it.
132+
.. versionadded:: 3.3
133+
This technique is discouraged and the ``addClassesToCompile()`` method was
134+
deprecated in Symfony 3.3 because modern PHP versions make it unnecessary.
137135

138136
Symfony creates a big ``classes.php`` file in the cache directory to aggregate
139137
the contents of the PHP classes that are used in every request. This reduces the

components/dependency_injection.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
The DependencyInjection Component
66
=================================
77

8-
The DependencyInjection component allows you to standardize and centralize
9-
the way objects are constructed in your application.
8+
The DependencyInjection component implements a `PSR-11`_ compatible service
9+
container that allows you to standardize and centralize the way objects are
10+
constructed in your application.
1011

1112
For an introduction to Dependency Injection and service containers see
1213
:doc:`/service_container`.
@@ -305,4 +306,5 @@ Learn More
305306
/components/dependency_injection/*
306307
/service_container/*
307308

309+
.. _`PSR-11`: http://www.php-fig.org/psr/psr-11/
308310
.. _Packagist: https://packagist.org/packages/symfony/dependency-injection

components/yaml.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ Add the ``--format`` option to get the output in JSON format:
368368
369369
$ php lint.php path/to/file.yml --format json
370370
371+
.. tip::
372+
373+
The linting command will also report any deprecations in the checked
374+
YAML files. This may for example be useful for recognizing deprecations of
375+
contents of YAML files during automated tests.
376+
371377
Learn More
372378
----------
373379

debug/debugging.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ cache files, or you can change the extension used by Symfony for these files::
6161

6262
$kernel->loadClassCache('classes', '.php.cache');
6363

64+
.. versionadded:: 3.3
65+
The ``loadClassCache()`` was deprecated in Symfony 3.3 and removed in
66+
Symfony 4.0. No alternative is provided because this feature is useless
67+
when using PHP 7 or higher.
68+
6469
Useful Debugging Commands
6570
-------------------------
6671

deployment/platformsh.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Platform.sh how to deploy your application (read more about
6464
mounts:
6565
'/var/cache': 'shared:files/cache'
6666
'/var/logs': 'shared:files/logs'
67+
'/var/sessions': 'shared:files/sessions'
6768
6869
# The hooks that will be performed when the package is deployed.
6970
hooks:

frontend/encore/shared-entry.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ on your page before any other JavaScript file:
3232
.. code-block:: twig
3333
3434
<!-- these two files now must be included in every page -->
35-
<script src="{{ asset('build/manifest.json') }}"></script>
35+
<script src="{{ asset('build/manifest.js') }}"></script>
3636
<script src="{{ asset('build/vendor.js') }}"></script>
3737
3838
<!-- here you link to the specific JS files needed by the current page -->
@@ -42,7 +42,7 @@ on your page before any other JavaScript file:
4242
<link rel="stylesheet" href="{{ asset('build/vendor.css') }}" />
4343
4444
The ``vendor.js`` file contains all the common code that has been extracted from
45-
the other files, so it's obvious that it must be included. The other file (``manifest.json``)
45+
the other files, so it's obvious that it must be included. The other file (``manifest.js``)
4646
is less obvious: it's needed so that Webpack knows how to load those shared modules.
4747

4848
.. tip::

serializer/encoders.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,23 @@ You can add new encoders to a Serializer instance by using its second constructo
2323
Built-in Encoders
2424
-----------------
2525

26-
Two encoders are used in the example above:
26+
The Serializer component provides built-in encoders:
2727

28-
* :class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder` to encode/decode XML
28+
* :class:`Symfony\\Component\\Serializer\\Encoder\\CsvEncoder` to encode/decode CSV
2929
* :class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder` to encode/decode JSON
30+
* :class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder` to encode/decode XML
31+
* :class:`Symfony\\Component\\Serializer\\Encoder\\YamlEncoder` to encode/decode Yaml
32+
33+
.. versionadded:: 3.2
34+
The :class:`Symfony\\Component\\Serializer\\Encoder\\CsvEncoder` and the
35+
:class:`Symfony\\Component\\Serializer\\Encoder\\YamlEncoder` were introduced in
36+
Symfony 3.2.
37+
38+
The ``JsonEncoder``
39+
~~~~~~~~~~~~~~~~~~~
40+
41+
The ``JsonEncoder`` encodes to and decodes from JSON strings, based on the PHP
42+
:phpfunction:`json_encode` and :phpfunction:`json_decode` functions.
3043

3144
The ``XmlEncoder``
3245
~~~~~~~~~~~~~~~~~~
@@ -56,8 +69,8 @@ Be aware that this encoder will consider keys beginning with ``@`` as attributes
5669
// <foo bar="value" />
5770
// </response>
5871

59-
The ``JsonEncoder``
72+
The ``YamlEncoder``
6073
~~~~~~~~~~~~~~~~~~~
6174

62-
The ``JsonEncoder`` is much simpler and is based on the PHP
63-
:phpfunction:`json_encode` and :phpfunction:`json_decode` functions.
75+
This encoder requires the :doc:`Yaml Component </components/yaml>` and
76+
transforms from and to Yaml.

service_container/3.3-di-changes.rst

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ which means it's always safe to upgrade across minor versions.
2222
All of the new features are **optional**: they are not enabled by default, so you
2323
need to actually change your configuration files to use them.
2424

25+
.. _`service-33-default_definition`:
26+
2527
The new Default services.yml File
2628
---------------------------------
2729

@@ -411,7 +413,7 @@ In general, the new best practice is to use normal constructor dependency inject
411413
4) Auto-tagging with autoconfigure
412414
----------------------------------
413415

414-
The last big change is the ``autoconfigure`` key, which is set to ``true`` under
416+
The fourth big change is the ``autoconfigure`` key, which is set to ``true`` under
415417
``_defaults``. Thanks to this, the container will auto-tag services registered in
416418
this file. For example, suppose you want to create an event subscriber. First, you
417419
create the class::
@@ -468,6 +470,59 @@ Many autoconfigured tags have an optional priority. If you need to specify a pri
468470
(or any other optional tag attribute), no problem! Just :ref:`manually configure your service <services-manually-wire-args>`
469471
and add the tag. Your tag will take precedence over the one added by auto-configuration.
470472

473+
5) Auto-configure with _instanceof
474+
----------------------------------
475+
476+
And the final big change is ``_instanceof``. It acts as a default definition
477+
template (see `service-33-default_definition`_), but only for services whose
478+
class matches a defined one.
479+
480+
This can be very useful when many services share some tag that cannot be
481+
inherited from an abstract definition:
482+
483+
.. configuration-block::
484+
485+
.. code-block:: yaml
486+
487+
# app/config/services.yml
488+
services:
489+
# ...
490+
491+
_instanceof:
492+
class: AppBundle\Domain\LoaderInterface
493+
public: true
494+
tags: ['app.domain_loader']
495+
496+
.. code-block:: xml
497+
498+
<!-- app/config/services.xml -->
499+
<?xml version="1.0" encoding="UTF-8" ?>
500+
<container xmlns="http://symfony.com/schema/dic/services"
501+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
502+
xsi:schemaLocation="http://symfony.com/schema/dic/services
503+
http://symfony.com/schema/dic/services/services-1.0.xsd">
504+
505+
<services>
506+
<!-- ... -->
507+
508+
<instanceof id="AppBundle\Domain\LoaderInterface" public="true">
509+
<tag name="app.domain_loader" />
510+
</instanceof>
511+
</services>
512+
</container>
513+
514+
.. code-block:: php
515+
516+
// app/config/services.php
517+
use AppBundle\Domain\LoaderInterface;
518+
519+
// ...
520+
521+
/* This method returns a child definition to define the default
522+
configuration of the given class or interface */
523+
$container->registerForAutoconfiguration(LoaderInterface::class)
524+
->addTag('app.domain_loader');
525+
471526
What about Performance
472527
----------------------
473528

service_container/service_locators.rst

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ A real-world example are applications that implement the `Command pattern`_
1414
using a CommandBus to map command handlers by Command class names and use them
1515
to handle their respective command when it is asked for::
1616

17+
// src/AppBundle/CommandBus.php
18+
namespace AppBundle;
19+
1720
// ...
1821
class CommandBus
1922
{
@@ -46,28 +49,29 @@ Considering that only one command is handled at a time, instantiating all the
4649
other command handlers is unnecessary. A possible solution to lazy-load the
4750
handlers could be to inject the whole dependency injection container::
4851

49-
use Symfony\Component\DependencyInjection\ContainerInterface;
52+
// ...
53+
use Symfony\Component\DependencyInjection\ContainerInterface;
5054

51-
class CommandBus
52-
{
53-
private $container;
55+
class CommandBus
56+
{
57+
private $container;
5458

55-
public function __construct(ContainerInterface $container)
56-
{
57-
$this->container = $container;
58-
}
59+
public function __construct(ContainerInterface $container)
60+
{
61+
$this->container = $container;
62+
}
5963

60-
public function handle(Command $command)
61-
{
62-
$commandClass = get_class($command);
64+
public function handle(Command $command)
65+
{
66+
$commandClass = get_class($command);
6367

64-
if ($this->container->has($commandClass)) {
65-
$handler = $this->container->get($commandClass);
68+
if ($this->container->has($commandClass)) {
69+
$handler = $this->container->get($commandClass);
6670

67-
return $handler->handle($command);
68-
}
71+
return $handler->handle($command);
6972
}
7073
}
74+
}
7175

7276
However, injecting the entire container is discouraged because it gives too
7377
broad access to existing services and it hides the actual dependencies of the
@@ -87,8 +91,8 @@ option to include as many services as needed to it and add the
8791

8892
.. code-block:: yaml
8993
94+
// app/config/services.yml
9095
services:
91-
9296
app.command_handler_locator:
9397
class: Symfony\Component\DependencyInjection\ServiceLocator
9498
tags: ['container.service_locator']
@@ -99,6 +103,7 @@ option to include as many services as needed to it and add the
99103
100104
.. code-block:: xml
101105
106+
<!-- app/config/services.xml -->
102107
<?xml version="1.0" encoding="UTF-8" ?>
103108
<container xmlns="http://symfony.com/schema/dic/services"
104109
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -119,6 +124,7 @@ option to include as many services as needed to it and add the
119124
120125
.. code-block:: php
121126
127+
// app/config/services.php
122128
use Symfony\Component\DependencyInjection\ServiceLocator;
123129
use Symfony\Component\DependencyInjection\Reference;
124130
@@ -144,13 +150,14 @@ Now you can use the service locator injecting it in any other service:
144150

145151
.. code-block:: yaml
146152
153+
// app/config/services.yml
147154
services:
148-
149155
AppBundle\CommandBus:
150156
arguments: ['@app.command_handler_locator']
151157
152158
.. code-block:: xml
153159
160+
<!-- app/config/services.xml -->
154161
<?xml version="1.0" encoding="UTF-8" ?>
155162
<container xmlns="http://symfony.com/schema/dic/services"
156163
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -159,19 +166,18 @@ Now you can use the service locator injecting it in any other service:
159166
<services>
160167
161168
<service id="AppBundle\CommandBus">
162-
<argument type="service" id="app.command_handler.locator" />
169+
<argument type="service" id="app.command_handler_locator" />
163170
</service>
164171
165172
</services>
166173
</container>
167174
168175
.. code-block:: php
169176
177+
// app/config/services.php
170178
use AppBundle\CommandBus;
171179
use Symfony\Component\DependencyInjection\Reference;
172180
173-
//...
174-
175181
$container
176182
->register(CommandBus::class)
177183
->setArguments(array(new Reference('app.command_handler_locator')))
@@ -185,7 +191,7 @@ Now you can use the service locator injecting it in any other service:
185191
Usage
186192
-----
187193

188-
Back to the previous CommandBus example, it looks like this when using the
194+
Back to the previous ``CommandBus`` example, it looks like this when using the
189195
service locator::
190196

191197
// ...

service_container/tags.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ that it implements ``Twig_ExtensionInterface``) and adds the tag for you.
7272

7373
.. tip::
7474

75-
To apply a tag to all your autoconfigured services extending a class or an
75+
To apply a tag to all your autoconfigured services extending a class or implementing an
7676
interface, call the :method:`Symfony\\Component\\DependencyInjection\\ContainerBuilder::registerForAutoconfiguration`
7777
method in an :doc:`extension </bundles/extension>` or from your kernel::
7878

0 commit comments

Comments
 (0)