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/DateTimeZoneNormalizer.php line 56

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\InvalidArgumentException;
  13. use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
  14. /**
  15.  * Normalizes a {@see \DateTimeZone} object to a timezone string.
  16.  *
  17.  * @author Jérôme Desjardins <jewome62@gmail.com>
  18.  */
  19. class DateTimeZoneNormalizer implements NormalizerInterfaceDenormalizerInterfaceCacheableSupportsMethodInterface
  20. {
  21.     /**
  22.      * {@inheritdoc}
  23.      *
  24.      * @return string
  25.      *
  26.      * @throws InvalidArgumentException
  27.      */
  28.     public function normalize($objectstring $format null, array $context = [])
  29.     {
  30.         if (!$object instanceof \DateTimeZone) {
  31.             throw new InvalidArgumentException('The object must be an instance of "\DateTimeZone".');
  32.         }
  33.         return $object->getName();
  34.     }
  35.     /**
  36.      * {@inheritdoc}
  37.      */
  38.     public function supportsNormalization($datastring $format null)
  39.     {
  40.         return $data instanceof \DateTimeZone;
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      *
  45.      * @return \DateTimeZone
  46.      *
  47.      * @throws NotNormalizableValueException
  48.      */
  49.     public function denormalize($datastring $typestring $format null, array $context = [])
  50.     {
  51.         if ('' === $data || null === $data) {
  52.             throw NotNormalizableValueException::createForUnexpectedDataType('The data is either an empty string or null, you should pass a string that can be parsed as a DateTimeZone.'$data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? nulltrue);
  53.         }
  54.         try {
  55.             return new \DateTimeZone($data);
  56.         } catch (\Exception $e) {
  57.             throw NotNormalizableValueException::createForUnexpectedDataType($e->getMessage(), $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? nulltrue$e->getCode(), $e);
  58.         }
  59.     }
  60.     /**
  61.      * {@inheritdoc}
  62.      */
  63.     public function supportsDenormalization($datastring $typestring $format null)
  64.     {
  65.         return \DateTimeZone::class === $type;
  66.     }
  67.     /**
  68.      * {@inheritdoc}
  69.      */
  70.     public function hasCacheableSupportsMethod(): bool
  71.     {
  72.         return __CLASS__ === static::class;
  73.     }
  74. }