Skip to content

Commit 48151d5

Browse files
committed
Merge branch '4.2' into 4.3
* 4.2: Updated Symfony Contracts package names and installation Update serializer.rst: deprecate the setCallbacks
2 parents 3b870e3 + cf458de commit 48151d5

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

components/contracts.rst

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@ The Contracts Component
1212
Installation
1313
------------
1414

15+
Contracts are provided as separate packages, so you can install only the ones
16+
your projects really need:
17+
1518
.. code-block:: terminal
1619
17-
$ composer require symfony/contracts
20+
$ composer require symfony/cache-contracts
21+
$ composer require symfony/event-dispatcher-contracts
22+
$ composer require symfony/http-client-contracts
23+
$ composer require symfony/service-contracts
24+
$ composer require symfony/translation-contracts
1825
1926
.. include:: /components/require_autoload.rst.inc
2027

@@ -45,15 +52,15 @@ Design Principles
4552
* Contracts must be backward compatible with existing Symfony components.
4653

4754
Packages that implement specific contracts should list them in the ``provide``
48-
section of their ``composer.json`` file, using the
49-
``symfony/*-contracts-implementation`` convention. For example:
55+
section of their ``composer.json`` file, using the ``symfony/*-implementation``
56+
convention. For example:
5057

5158
.. code-block:: javascript
5259
5360
{
5461
"...": "...",
5562
"provide": {
56-
"symfony/cache-contracts-implementation": "1.0"
63+
"symfony/cache-implementation": "1.0"
5764
}
5865
}
5966
@@ -68,23 +75,4 @@ However, PHP-FIG has different goals and different processes. Symfony Contracts
6875
focuses on providing abstractions that are useful on their own while still
6976
compatible with implementations provided by Symfony.
7077

71-
Why Isn't this Package Split into Several Packages?
72-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73-
74-
Putting all interfaces in one package eases discoverability and dependency
75-
management. Instead of dealing with a myriad of small packages and the
76-
corresponding matrix of versions, you only deal with one package and one
77-
version. Also when using IDE autocompletion or reading the source code, it makes
78-
it easier to figure out which contracts are provided.
79-
80-
There are two downsides to this approach:
81-
82-
* You may have unused files in your ``vendor/`` directory. This has no impact in
83-
practice because the file sizes are very small and there is no performance
84-
overhead at all since they are never loaded.
85-
* In the future, it will be impossible to use two different sub-namespaces in
86-
different major versions of the package. However, this package follows the
87-
:doc:`Symfony BC + deprecation </contributing/code/bc>` policies, with an
88-
additional restriction to never remove deprecated interfaces.
89-
9078
.. _`PHP-FIG`: https://www.php-fig.org/

components/serializer.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,12 @@ and ``remove``.
639639
Using Callbacks to Serialize Properties with Object Instances
640640
-------------------------------------------------------------
641641

642+
.. deprecated:: 4.2
643+
644+
The :method:`Symfony\\Component\\Serializer\\Normalizer\\AbstractNormalizer::setCallbacks`
645+
method is deprecated since Symfony 4.2. Use the ``callbacks``
646+
key of the context instead.
647+
642648
When serializing, you can set a callback to format a specific object property::
643649

644650
use App\Model\Person;
@@ -647,14 +653,19 @@ When serializing, you can set a callback to format a specific object property::
647653
use Symfony\Component\Serializer\Serializer;
648654

649655
$encoder = new JsonEncoder();
650-
$normalizer = new GetSetMethodNormalizer();
651656

652657
// all callback parameters are optional (you can omit the ones you don't use)
653658
$callback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
654659
return $innerObject instanceof \DateTime ? $innerObject->format(\DateTime::ISO8601) : '';
655660
};
656661

657-
$normalizer->setCallbacks(['createdAt' => $callback]);
662+
$defaultContext = [
663+
AbstractNormalizer::CALLBACKS => [
664+
'createdAt' => $callback,
665+
],
666+
];
667+
668+
$normalizer = new GetSetMethodNormalizer(null, null, null, null, null, $defaultContext);
658669

659670
$serializer = new Serializer([$normalizer], [$encoder]);
660671

0 commit comments

Comments
 (0)