Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
+86 -82
View File
@@ -13,11 +13,17 @@ namespace Symfony\Component\Serializer;
use Symfony\Component\Serializer\Encoder\ChainDecoder;
use Symfony\Component\Serializer\Encoder\ChainEncoder;
use Symfony\Component\Serializer\Encoder\ContextAwareDecoderInterface;
use Symfony\Component\Serializer\Encoder\ContextAwareEncoderInterface;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Exception\LogicException;
use Symfony\Component\Serializer\Exception\NotEncodableValueException;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\ContextAwareDenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
@@ -38,7 +44,7 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class Serializer implements SerializerInterface, NormalizerInterface, DenormalizerInterface, EncoderInterface, DecoderInterface
class Serializer implements SerializerInterface, ContextAwareNormalizerInterface, ContextAwareDenormalizerInterface, ContextAwareEncoderInterface, ContextAwareDecoderInterface
{
/**
* @var Encoder\ChainEncoder
@@ -51,24 +57,18 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
protected $decoder;
/**
* @var array
* @internal since Symfony 4.1
*/
protected $normalizers = [];
/**
* @var array
*
* @deprecated since 3.1 will be removed in 4.0
*/
protected $normalizerCache = [];
private $cachedNormalizers;
private $denormalizerCache = [];
private $normalizerCache = [];
/**
* @var array
*
* @deprecated since 3.1 will be removed in 4.0
* @param array<NormalizerInterface|DenormalizerInterface> $normalizers
* @param array<EncoderInterface|DecoderInterface> $encoders
*/
protected $denormalizerCache = [];
public function __construct(array $normalizers = [], array $encoders = [])
{
foreach ($normalizers as $normalizer) {
@@ -83,6 +83,11 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
if ($normalizer instanceof NormalizerAwareInterface) {
$normalizer->setNormalizer($this);
}
if (!($normalizer instanceof NormalizerInterface || $normalizer instanceof DenormalizerInterface)) {
@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);
// throw new \InvalidArgumentException(sprintf('The class "%s" does not implement "%s" or "%s".', \get_class($normalizer), NormalizerInterface::class, DenormalizerInterface::class));
}
}
$this->normalizers = $normalizers;
@@ -98,6 +103,11 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
if ($encoder instanceof EncoderInterface) {
$realEncoders[] = $encoder;
}
if (!($encoder instanceof EncoderInterface || $encoder instanceof DecoderInterface)) {
@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);
// throw new \InvalidArgumentException(sprintf('The class "%s" does not implement "%s" or "%s".', \get_class($normalizer), EncoderInterface::class, DecoderInterface::class));
}
}
$this->encoder = new ChainEncoder($realEncoders);
$this->decoder = new ChainDecoder($decoders);
@@ -106,7 +116,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
/**
* {@inheritdoc}
*/
final public function serialize($data, $format, array $context = [])
final public function serialize($data, $format, array $context = []): string
{
if (!$this->supportsEncoding($format, $context)) {
throw new NotEncodableValueException(sprintf('Serialization for the format "%s" is not supported.', $format));
@@ -143,11 +153,15 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
return $normalizer->normalize($data, $format, $context);
}
if (null === $data || is_scalar($data)) {
if (null === $data || \is_scalar($data)) {
return $data;
}
if (\is_array($data) || $data instanceof \Traversable) {
if (is_iterable($data)) {
if (($context[AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS] ?? false) === true && $data instanceof \Countable && 0 === $data->count()) {
return $data;
}
$normalized = [];
foreach ($data as $key => $val) {
$normalized[$key] = $this->normalize($val, $format, $context);
@@ -188,42 +202,16 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null/*, array $context = []*/)
public function supportsNormalization($data, $format = null, array $context = [])
{
if (\func_num_args() > 2) {
$context = func_get_arg(2);
} else {
if (__CLASS__ !== static::class) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('The "%s()" method will have a third `$context = []` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), \E_USER_DEPRECATED);
}
}
$context = [];
}
return null !== $this->getNormalizer($data, $format, $context);
}
/**
* {@inheritdoc}
*/
public function supportsDenormalization($data, $type, $format = null/*, array $context = []*/)
public function supportsDenormalization($data, $type, $format = null, array $context = [])
{
if (\func_num_args() > 3) {
$context = func_get_arg(3);
} else {
if (__CLASS__ !== static::class) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('The "%s()" method will have a fourth `$context = []` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), \E_USER_DEPRECATED);
}
}
$context = [];
}
return null !== $this->getDenormalizer($data, $type, $format, $context);
}
@@ -233,13 +221,35 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
* @param mixed $data Data to get the serializer for
* @param string $format Format name, present to give the option to normalizers to act differently based on formats
* @param array $context Options available to the normalizer
*
* @return NormalizerInterface|null
*/
private function getNormalizer($data, $format, array $context)
private function getNormalizer($data, ?string $format, array $context): ?NormalizerInterface
{
foreach ($this->normalizers as $normalizer) {
if ($normalizer instanceof NormalizerInterface && $normalizer->supportsNormalization($data, $format, $context)) {
if ($this->cachedNormalizers !== $this->normalizers) {
$this->cachedNormalizers = $this->normalizers;
$this->denormalizerCache = $this->normalizerCache = [];
}
$type = \is_object($data) ? \get_class($data) : 'native-'.\gettype($data);
if (!isset($this->normalizerCache[$format][$type])) {
$this->normalizerCache[$format][$type] = [];
foreach ($this->normalizers as $k => $normalizer) {
if (!$normalizer instanceof NormalizerInterface) {
continue;
}
if (!$normalizer instanceof CacheableSupportsMethodInterface || !$normalizer->hasCacheableSupportsMethod()) {
$this->normalizerCache[$format][$type][$k] = false;
} elseif ($normalizer->supportsNormalization($data, $format, $context)) {
$this->normalizerCache[$format][$type][$k] = true;
break;
}
}
}
foreach ($this->normalizerCache[$format][$type] as $k => $cached) {
$normalizer = $this->normalizers[$k];
if ($cached || $normalizer->supportsNormalization($data, $format, $context)) {
return $normalizer;
}
}
@@ -254,13 +264,33 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
* @param string $class The expected class to instantiate
* @param string $format Format name, present to give the option to normalizers to act differently based on formats
* @param array $context Options available to the denormalizer
*
* @return DenormalizerInterface|null
*/
private function getDenormalizer($data, $class, $format, array $context)
private function getDenormalizer($data, string $class, ?string $format, array $context): ?DenormalizerInterface
{
foreach ($this->normalizers as $normalizer) {
if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $class, $format, $context)) {
if ($this->cachedNormalizers !== $this->normalizers) {
$this->cachedNormalizers = $this->normalizers;
$this->denormalizerCache = $this->normalizerCache = [];
}
if (!isset($this->denormalizerCache[$format][$class])) {
$this->denormalizerCache[$format][$class] = [];
foreach ($this->normalizers as $k => $normalizer) {
if (!$normalizer instanceof DenormalizerInterface) {
continue;
}
if (!$normalizer instanceof CacheableSupportsMethodInterface || !$normalizer->hasCacheableSupportsMethod()) {
$this->denormalizerCache[$format][$class][$k] = false;
} elseif ($normalizer->supportsDenormalization(null, $class, $format, $context)) {
$this->denormalizerCache[$format][$class][$k] = true;
break;
}
}
}
foreach ($this->denormalizerCache[$format][$class] as $k => $cached) {
$normalizer = $this->normalizers[$k];
if ($cached || $normalizer->supportsDenormalization($data, $class, $format, $context)) {
return $normalizer;
}
}
@@ -287,42 +317,16 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
/**
* {@inheritdoc}
*/
public function supportsEncoding($format/*, array $context = []*/)
public function supportsEncoding($format, array $context = [])
{
if (\func_num_args() > 1) {
$context = func_get_arg(1);
} else {
if (__CLASS__ !== static::class) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('The "%s()" method will have a second `$context = []` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), \E_USER_DEPRECATED);
}
}
$context = [];
}
return $this->encoder->supportsEncoding($format, $context);
}
/**
* {@inheritdoc}
*/
public function supportsDecoding($format/*, array $context = []*/)
public function supportsDecoding($format, array $context = [])
{
if (\func_num_args() > 1) {
$context = func_get_arg(1);
} else {
if (__CLASS__ !== static::class) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('The "%s()" method will have a second `$context = []` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), \E_USER_DEPRECATED);
}
}
$context = [];
}
return $this->decoder->supportsDecoding($format, $context);
}
}