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/MimeMessageNormalizer.php line 113

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\Mime\Address;
  12. use Symfony\Component\Mime\Header\HeaderInterface;
  13. use Symfony\Component\Mime\Header\Headers;
  14. use Symfony\Component\Mime\Header\UnstructuredHeader;
  15. use Symfony\Component\Mime\Message;
  16. use Symfony\Component\Mime\Part\AbstractPart;
  17. use Symfony\Component\Serializer\SerializerAwareInterface;
  18. use Symfony\Component\Serializer\SerializerInterface;
  19. /**
  20.  * Normalize Mime message classes.
  21.  *
  22.  * It forces the use of a PropertyNormalizer instance for normalization
  23.  * of all data objects composing a Message.
  24.  *
  25.  * Emails using resources for any parts are not serializable.
  26.  */
  27. final class MimeMessageNormalizer implements NormalizerInterfaceDenormalizerInterfaceSerializerAwareInterfaceCacheableSupportsMethodInterface
  28. {
  29.     private $serializer;
  30.     private $normalizer;
  31.     private $headerClassMap;
  32.     private $headersProperty;
  33.     public function __construct(PropertyNormalizer $normalizer)
  34.     {
  35.         $this->normalizer $normalizer;
  36.         $this->headerClassMap = (new \ReflectionClassConstant(Headers::class, 'HEADER_CLASS_MAP'))->getValue();
  37.         $this->headersProperty = new \ReflectionProperty(Headers::class, 'headers');
  38.         $this->headersProperty->setAccessible(true);
  39.     }
  40.     public function setSerializer(SerializerInterface $serializer)
  41.     {
  42.         $this->serializer $serializer;
  43.         $this->normalizer->setSerializer($serializer);
  44.     }
  45.     /**
  46.      * {@inheritdoc}
  47.      */
  48.     public function normalize($objectstring $format null, array $context = [])
  49.     {
  50.         if ($object instanceof Headers) {
  51.             $ret = [];
  52.             foreach ($this->headersProperty->getValue($object) as $name => $header) {
  53.                 $ret[$name] = $this->serializer->normalize($header$format$context);
  54.             }
  55.             return $ret;
  56.         }
  57.         if ($object instanceof AbstractPart) {
  58.             $ret $this->normalizer->normalize($object$format$context);
  59.             $ret['class'] = \get_class($object);
  60.             unset($ret['seekable'], $ret['cid'], $ret['handle']);
  61.             return $ret;
  62.         }
  63.         return $this->normalizer->normalize($object$format$context);
  64.     }
  65.     /**
  66.      * {@inheritdoc}
  67.      */
  68.     public function denormalize($datastring $typestring $format null, array $context = [])
  69.     {
  70.         if (Headers::class === $type) {
  71.             $ret = [];
  72.             foreach ($data as $headers) {
  73.                 foreach ($headers as $header) {
  74.                     $ret[] = $this->serializer->denormalize($header$this->headerClassMap[strtolower($header['name'])] ?? UnstructuredHeader::class, $format$context);
  75.                 }
  76.             }
  77.             return new Headers(...$ret);
  78.         }
  79.         if (AbstractPart::class === $type) {
  80.             $type $data['class'];
  81.             unset($data['class']);
  82.             $data['headers'] = $this->serializer->denormalize($data['headers'], Headers::class, $format$context);
  83.         }
  84.         return $this->normalizer->denormalize($data$type$format$context);
  85.     }
  86.     /**
  87.      * {@inheritdoc}
  88.      */
  89.     public function supportsNormalization($datastring $format null): bool
  90.     {
  91.         return $data instanceof Message || $data instanceof Headers || $data instanceof HeaderInterface || $data instanceof Address || $data instanceof AbstractPart;
  92.     }
  93.     /**
  94.      * {@inheritdoc}
  95.      */
  96.     public function supportsDenormalization($datastring $typestring $format null): bool
  97.     {
  98.         return is_a($typeMessage::class, true) || Headers::class === $type || AbstractPart::class === $type;
  99.     }
  100.     /**
  101.      * {@inheritdoc}
  102.      */
  103.     public function hasCacheableSupportsMethod(): bool
  104.     {
  105.         return __CLASS__ === static::class;
  106.     }
  107. }