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/UidNormalizer.php line 88

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\LogicException;
  13. use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
  14. use Symfony\Component\Uid\AbstractUid;
  15. use Symfony\Component\Uid\Uuid;
  16. final class UidNormalizer implements NormalizerInterfaceDenormalizerInterfaceCacheableSupportsMethodInterface
  17. {
  18.     public const NORMALIZATION_FORMAT_KEY 'uid_normalization_format';
  19.     public const NORMALIZATION_FORMAT_CANONICAL 'canonical';
  20.     public const NORMALIZATION_FORMAT_BASE58 'base58';
  21.     public const NORMALIZATION_FORMAT_BASE32 'base32';
  22.     public const NORMALIZATION_FORMAT_RFC4122 'rfc4122';
  23.     private $defaultContext = [
  24.         self::NORMALIZATION_FORMAT_KEY => self::NORMALIZATION_FORMAT_CANONICAL,
  25.     ];
  26.     public function __construct(array $defaultContext = [])
  27.     {
  28.         $this->defaultContext array_merge($this->defaultContext$defaultContext);
  29.     }
  30.     /**
  31.      * {@inheritdoc}
  32.      *
  33.      * @param AbstractUid $object
  34.      */
  35.     public function normalize($objectstring $format null, array $context = [])
  36.     {
  37.         switch ($context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY]) {
  38.             case self::NORMALIZATION_FORMAT_CANONICAL:
  39.                 return (string) $object;
  40.             case self::NORMALIZATION_FORMAT_BASE58:
  41.                 return $object->toBase58();
  42.             case self::NORMALIZATION_FORMAT_BASE32:
  43.                 return $object->toBase32();
  44.             case self::NORMALIZATION_FORMAT_RFC4122:
  45.                 return $object->toRfc4122();
  46.         }
  47.         throw new LogicException(sprintf('The "%s" format is not valid.'$context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY]));
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function supportsNormalization($datastring $format null): bool
  53.     {
  54.         return $data instanceof AbstractUid;
  55.     }
  56.     /**
  57.      * {@inheritdoc}
  58.      */
  59.     public function denormalize($datastring $typestring $format null, array $context = [])
  60.     {
  61.         try {
  62.             return AbstractUid::class !== $type $type::fromString($data) : Uuid::fromString($data);
  63.         } catch (\InvalidArgumentException|\TypeError $exception) {
  64.             throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The data is not a valid "%s" string representation.'$type), $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? nulltrue);
  65.         } catch (\Error $e) {
  66.             if (str_starts_with($e->getMessage(), 'Cannot instantiate abstract class')) {
  67.                 return $this->denormalize($dataAbstractUid::class, $format$context);
  68.             }
  69.             throw $e;
  70.         }
  71.     }
  72.     /**
  73.      * {@inheritdoc}
  74.      */
  75.     public function supportsDenormalization($datastring $typestring $format null): bool
  76.     {
  77.         return is_a($typeAbstractUid::class, true);
  78.     }
  79.     /**
  80.      * {@inheritdoc}
  81.      */
  82.     public function hasCacheableSupportsMethod(): bool
  83.     {
  84.         return __CLASS__ === static::class;
  85.     }
  86. }