vendor/api-platform/core/src/Core/Bridge/RamseyUuid/Identifier/Normalizer/UuidNormalizer.php line 30

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.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. declare(strict_types=1);
  11. namespace ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer;
  12. use ApiPlatform\Exception\InvalidIdentifierException;
  13. use ApiPlatform\RamseyUuid\UriVariableTransformer\UuidUriVariableTransformer;
  14. use Ramsey\Uuid\Exception\InvalidUuidStringException;
  15. use Ramsey\Uuid\Uuid;
  16. use Ramsey\Uuid\UuidInterface;
  17. use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
  18. /**
  19.  * Denormalizes an UUID string to an instance of Ramsey\Uuid.
  20.  *
  21.  * @author Antoine Bluchet <soyuka@gmail.com>
  22.  */
  23. final class UuidNormalizer implements DenormalizerInterface
  24. {
  25.     public function __construct()
  26.     {
  27.         trigger_deprecation('api-platform/core''2.7'sprintf('The class "%s" will be replaced by "%s".'self::class, UuidUriVariableTransformer::class));
  28.     }
  29.     /**
  30.      * @param string $class
  31.      * @param null   $format
  32.      *
  33.      * @throws InvalidIdentifierException
  34.      */
  35.     public function denormalize($data$class$format null, array $context = [])
  36.     {
  37.         try {
  38.             return Uuid::fromString($data);
  39.         } catch (InvalidUuidStringException $e) {
  40.             throw new InvalidIdentifierException($e->getMessage(), $e->getCode(), $e);
  41.         }
  42.     }
  43.     public function supportsDenormalization($data$type$format null, array $context = []): bool
  44.     {
  45.         return \is_string($data) && is_a($typeUuidInterface::class, true);
  46.     }
  47. }