Deprecated: Constant E_STRICT is deprecated in /home/normanv/www/annuairepro/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /home/normanv/www/annuairepro/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

vendor/symfony/serializer/Normalizer/ArrayDenormalizer.php line 38

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Serializer\Normalizer;
  11. use Symfony\Component\PropertyInfo\Type;
  12. use Symfony\Component\Serializer\Exception\BadMethodCallException;
  13. use Symfony\Component\Serializer\Exception\InvalidArgumentException;
  14. use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
  15. use Symfony\Component\Serializer\Serializer;
  16. use Symfony\Component\Serializer\SerializerAwareInterface;
  17. use Symfony\Component\Serializer\SerializerInterface;
  18. /**
  19.  * Denormalizes arrays of objects.
  20.  *
  21.  * @author Alexander M. Turek <me@derrabus.de>
  22.  *
  23.  * @final
  24.  */
  25. class ArrayDenormalizer implements ContextAwareDenormalizerInterfaceDenormalizerAwareInterfaceSerializerAwareInterfaceCacheableSupportsMethodInterface
  26. {
  27.     use DenormalizerAwareTrait;
  28.     /**
  29.      * {@inheritdoc}
  30.      *
  31.      * @throws NotNormalizableValueException
  32.      */
  33.     public function denormalize($datastring $typestring $format null, array $context = []): array
  34.     {
  35.         if (null === $this->denormalizer) {
  36.             throw new BadMethodCallException('Please set a denormalizer before calling denormalize()!');
  37.         }
  38.         if (!\is_array($data)) {
  39.             throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('Data expected to be "%s", "%s" given.'$typeget_debug_type($data)), $data, [Type::BUILTIN_TYPE_ARRAY], $context['deserialization_path'] ?? null);
  40.         }
  41.         if (!str_ends_with($type'[]')) {
  42.             throw new InvalidArgumentException('Unsupported class: '.$type);
  43.         }
  44.         $type substr($type0, -2);
  45.         $builtinTypes array_map(static function (Type $keyType) {
  46.             return $keyType->getBuiltinType();
  47.         }, \is_array($keyType $context['key_type'] ?? []) ? $keyType : [$keyType]);
  48.         foreach ($data as $key => $value) {
  49.             $subContext $context;
  50.             $subContext['deserialization_path'] = ($context['deserialization_path'] ?? false) ? sprintf('%s[%s]'$context['deserialization_path'], $key) : "[$key]";
  51.             $this->validateKeyType($builtinTypes$key$subContext['deserialization_path']);
  52.             $data[$key] = $this->denormalizer->denormalize($value$type$format$subContext);
  53.         }
  54.         return $data;
  55.     }
  56.     /**
  57.      * {@inheritdoc}
  58.      */
  59.     public function supportsDenormalization($datastring $typestring $format null, array $context = []): bool
  60.     {
  61.         if (null === $this->denormalizer) {
  62.             throw new BadMethodCallException(sprintf('The nested denormalizer needs to be set to allow "%s()" to be used.'__METHOD__));
  63.         }
  64.         return str_ends_with($type'[]')
  65.             && $this->denormalizer->supportsDenormalization($datasubstr($type0, -2), $format$context);
  66.     }
  67.     /**
  68.      * {@inheritdoc}
  69.      *
  70.      * @deprecated call setDenormalizer() instead
  71.      */
  72.     public function setSerializer(SerializerInterface $serializer)
  73.     {
  74.         if (!$serializer instanceof DenormalizerInterface) {
  75.             throw new InvalidArgumentException('Expected a serializer that also implements DenormalizerInterface.');
  76.         }
  77.         if (Serializer::class !== debug_backtrace()[1]['class'] ?? null) {
  78.             trigger_deprecation('symfony/serializer''5.3''Calling "%s()" is deprecated. Please call setDenormalizer() instead.'__METHOD__);
  79.         }
  80.         $this->setDenormalizer($serializer);
  81.     }
  82.     /**
  83.      * {@inheritdoc}
  84.      */
  85.     public function hasCacheableSupportsMethod(): bool
  86.     {
  87.         return $this->denormalizer instanceof CacheableSupportsMethodInterface && $this->denormalizer->hasCacheableSupportsMethod();
  88.     }
  89.     /**
  90.      * @param mixed $key
  91.      */
  92.     private function validateKeyType(array $builtinTypes$keystring $path): void
  93.     {
  94.         if (!$builtinTypes) {
  95.             return;
  96.         }
  97.         foreach ($builtinTypes as $builtinType) {
  98.             if (('is_'.$builtinType)($key)) {
  99.                 return;
  100.             }
  101.         }
  102.         throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the key "%s" must be "%s" ("%s" given).'$keyimplode('", "'$builtinTypes), get_debug_type($key)), $key$builtinTypes$pathtrue);
  103.     }
  104. }