vendor/symfony/serializer/Mapping/ClassMetadata.php line 52

  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\Mapping;
  11. /**
  12.  * @author Kévin Dunglas <dunglas@gmail.com>
  13.  */
  14. class ClassMetadata implements ClassMetadataInterface
  15. {
  16.     /**
  17.      * @internal This property is public in order to reduce the size of the
  18.      *           class' serialized representation. Do not access it. Use
  19.      *           {@link getName()} instead.
  20.      */
  21.     public $name;
  22.     /**
  23.      * @var AttributeMetadataInterface[]
  24.      *
  25.      * @internal This property is public in order to reduce the size of the
  26.      *           class' serialized representation. Do not access it. Use
  27.      *           {@link getAttributesMetadata()} instead.
  28.      */
  29.     public $attributesMetadata = [];
  30.     /**
  31.      * @var \ReflectionClass
  32.      */
  33.     private $reflClass;
  34.     /**
  35.      * @var ClassDiscriminatorMapping|null
  36.      *
  37.      * @internal This property is public in order to reduce the size of the
  38.      *           class' serialized representation. Do not access it. Use
  39.      *           {@link getClassDiscriminatorMapping()} instead.
  40.      */
  41.     public $classDiscriminatorMapping;
  42.     /**
  43.      * Constructs a metadata for the given class.
  44.      */
  45.     public function __construct(string $classClassDiscriminatorMapping $classDiscriminatorMapping null)
  46.     {
  47.         $this->name $class;
  48.         $this->classDiscriminatorMapping $classDiscriminatorMapping;
  49.     }
  50.     public function getName(): string
  51.     {
  52.         return $this->name;
  53.     }
  54.     public function addAttributeMetadata(AttributeMetadataInterface $attributeMetadata)
  55.     {
  56.         $this->attributesMetadata[$attributeMetadata->getName()] = $attributeMetadata;
  57.     }
  58.     public function getAttributesMetadata(): array
  59.     {
  60.         return $this->attributesMetadata;
  61.     }
  62.     public function merge(ClassMetadataInterface $classMetadata)
  63.     {
  64.         foreach ($classMetadata->getAttributesMetadata() as $attributeMetadata) {
  65.             if (isset($this->attributesMetadata[$attributeMetadata->getName()])) {
  66.                 $this->attributesMetadata[$attributeMetadata->getName()]->merge($attributeMetadata);
  67.             } else {
  68.                 $this->addAttributeMetadata($attributeMetadata);
  69.             }
  70.         }
  71.     }
  72.     public function getReflectionClass(): \ReflectionClass
  73.     {
  74.         if (!$this->reflClass) {
  75.             $this->reflClass = new \ReflectionClass($this->getName());
  76.         }
  77.         return $this->reflClass;
  78.     }
  79.     public function getClassDiscriminatorMapping(): ?ClassDiscriminatorMapping
  80.     {
  81.         return $this->classDiscriminatorMapping;
  82.     }
  83.     public function setClassDiscriminatorMapping(ClassDiscriminatorMapping $mapping null)
  84.     {
  85.         if (\func_num_args()) {
  86.             trigger_deprecation('symfony/serializer''6.2''Calling "%s()" without any arguments is deprecated, pass null explicitly instead.'__METHOD__);
  87.         }
  88.         $this->classDiscriminatorMapping $mapping;
  89.     }
  90.     /**
  91.      * Returns the names of the properties that should be serialized.
  92.      *
  93.      * @return string[]
  94.      */
  95.     public function __sleep(): array
  96.     {
  97.         return [
  98.             'name',
  99.             'attributesMetadata',
  100.             'classDiscriminatorMapping',
  101.         ];
  102.     }
  103. }