vendor/api-platform/core/src/Core/Bridge/Symfony/Identifier/Normalizer/UlidNormalizer.php line 28

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\Symfony\Identifier\Normalizer;
  12. use ApiPlatform\Exception\InvalidIdentifierException;
  13. use ApiPlatform\Symfony\UriVariableTransformer\UlidUriVariableTransformer;
  14. use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
  15. use Symfony\Component\Uid\Ulid;
  16. /**
  17.  * Denormalizes an ULID string to an instance of Symfony\Component\Uid\Ulid.
  18.  */
  19. final class UlidNormalizer implements DenormalizerInterface
  20. {
  21.     public function __construct()
  22.     {
  23.         trigger_deprecation('api-platform/core''2.7'sprintf('The class "%s" will be replaced by "%s".'self::class, UlidUriVariableTransformer::class));
  24.     }
  25.     public function denormalize($data$class$format null, array $context = [])
  26.     {
  27.         try {
  28.             return Ulid::fromString($data);
  29.         } catch (\InvalidArgumentException $e) {
  30.             throw new InvalidIdentifierException($e->getMessage(), $e->getCode(), $e);
  31.         }
  32.     }
  33.     public function supportsDenormalization($data$type$format null, array $context = []): bool
  34.     {
  35.         return \is_string($data) && is_a($typeUlid::class, true);
  36.     }
  37. }