You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #27819 [Serializer] deprecated normalizers and encoders who dont implement the base interfaces (rodnaph)
This PR was merged into the 4.2-dev branch.
Discussion
----------
[Serializer] deprecated normalizers and encoders who dont implement the base interfaces
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | None
| License | MIT
| Doc PR | None
Currently the `Serializer` can be constructed with any object regardless of whether or not it implements `NormalizerInterface` or `DenormalizerInterface`. This object will then be ignored when getting a normalizer/denormalizer, so in effect silently ignored for serializer operations.
This change throws an exception on construct if a given normalizer object does not implement one of these interfaces - are there use cases where this would not be true?
Commits
-------
cbc2be8 [Serializer] deprecated normalizers and encoders who dont implement the base interfaces
@@ -78,6 +82,11 @@ public function __construct(array $normalizers = array(), array $encoders = arra
78
82
if ($normalizerinstanceof NormalizerAwareInterface) {
79
83
$normalizer->setNormalizer($this);
80
84
}
85
+
86
+
if (!($normalizerinstanceof NormalizerInterface || $normalizerinstanceof DenormalizerInterface)) {
87
+
@trigger_error(\sprintf('Passing normalizers ("%s") which do not implement either "%s" or "%s" has been deprecated since Symfony 4.2.', \get_class($normalizer), NormalizerInterface::class, DenormalizerInterface::class), E_USER_DEPRECATED);
88
+
// throw new \InvalidArgumentException(\sprintf('The class "%s" does not implement "%s" or "%s".', \get_class($normalizer), NormalizerInterface::class, DenormalizerInterface::class));
89
+
}
81
90
}
82
91
$this->normalizers = $normalizers;
83
92
@@ -93,6 +102,11 @@ public function __construct(array $normalizers = array(), array $encoders = arra
93
102
if ($encoderinstanceof EncoderInterface) {
94
103
$realEncoders[] = $encoder;
95
104
}
105
+
106
+
if (!($encoderinstanceof EncoderInterface || $encoderinstanceof DecoderInterface)) {
107
+
@trigger_error(\sprintf('Passing encoders ("%s") which do not implement either "%s" or "%s" has been deprecated since Symfony 4.2.', \get_class($encoder), EncoderInterface::class, DecoderInterface::class), E_USER_DEPRECATED);
108
+
// throw new \InvalidArgumentException(\sprintf('The class "%s" does not implement "%s" or "%s".', \get_class($normalizer), EncoderInterface::class, DecoderInterface::class));
* @expectedDeprecation Passing normalizers ("stdClass") which do not implement either "Symfony\Component\Serializer\Normalizer\NormalizerInterface" or "Symfony\Component\Serializer\Normalizer\DenormalizerInterface" has been deprecated since Symfony 4.2.
* @expectedDeprecation Passing encoders ("stdClass") which do not implement either "Symfony\Component\Serializer\Encoder\EncoderInterface" or "Symfony\Component\Serializer\Encoder\DecoderInterface" has been deprecated since Symfony 4.2.
0 commit comments