Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AttributeMetadata.php

class AttributeMetadata

@author Kévin Dunglas <dunglas@gmail.com>

Hierarchy

  • class \Symfony\Component\Serializer\Mapping\AttributeMetadata implements \Symfony\Component\Serializer\Mapping\AttributeMetadataInterface

Expanded class hierarchy of AttributeMetadata

5 files declare their use of AttributeMetadata
AttributeLoader.php in vendor/symfony/serializer/Mapping/Loader/AttributeLoader.php
CompiledClassMetadataFactory.php in vendor/symfony/serializer/Mapping/Factory/CompiledClassMetadataFactory.php
ObjectNormalizer.php in vendor/symfony/serializer/Normalizer/ObjectNormalizer.php
XmlFileLoader.php in vendor/symfony/serializer/Mapping/Loader/XmlFileLoader.php
YamlFileLoader.php in vendor/symfony/serializer/Mapping/Loader/YamlFileLoader.php

File

vendor/symfony/serializer/Mapping/AttributeMetadata.php, line 19

Namespace

Symfony\Component\Serializer\Mapping
View source
class AttributeMetadata implements AttributeMetadataInterface {
    
    /**
     * @internal This property is public in order to reduce the size of the
     *           class' serialized representation. Do not access it. Use
     *           {@link getName()} instead.
     */
    public string $name;
    
    /**
     * @internal This property is public in order to reduce the size of the
     *           class' serialized representation. Do not access it. Use
     *           {@link getGroups()} instead.
     */
    public array $groups = [];
    
    /**
     * @internal This property is public in order to reduce the size of the
     *           class' serialized representation. Do not access it. Use
     *           {@link getMaxDepth()} instead.
     */
    public ?int $maxDepth = null;
    
    /**
     * @internal This property is public in order to reduce the size of the
     *           class' serialized representation. Do not access it. Use
     *           {@link getSerializedName()} instead.
     */
    public ?string $serializedName = null;
    
    /**
     * @internal This property is public in order to reduce the size of the
     *           class' serialized representation. Do not access it. Use
     *           {@link getSerializedPath()} instead.
     */
    public ?PropertyPath $serializedPath = null;
    
    /**
     * @internal This property is public in order to reduce the size of the
     *           class' serialized representation. Do not access it. Use
     *           {@link isIgnored()} instead.
     */
    public bool $ignore = false;
    
    /**
     * @var array[] Normalization contexts per group name ("*" applies to all groups)
     *
     * @internal This property is public in order to reduce the size of the
     *           class' serialized representation. Do not access it. Use
     *           {@link getNormalizationContexts()} instead.
     */
    public array $normalizationContexts = [];
    
    /**
     * @var array[] Denormalization contexts per group name ("*" applies to all groups)
     *
     * @internal This property is public in order to reduce the size of the
     *           class' serialized representation. Do not access it. Use
     *           {@link getDenormalizationContexts()} instead.
     */
    public array $denormalizationContexts = [];
    public function __construct(string $name) {
        $this->name = $name;
    }
    public function getName() : string {
        return $this->name;
    }
    public function addGroup(string $group) : void {
        if (!\in_array($group, $this->groups, true)) {
            $this->groups[] = $group;
        }
    }
    public function getGroups() : array {
        return $this->groups;
    }
    public function setMaxDepth(?int $maxDepth) : void {
        $this->maxDepth = $maxDepth;
    }
    public function getMaxDepth() : ?int {
        return $this->maxDepth;
    }
    public function setSerializedName(?string $serializedName) : void {
        $this->serializedName = $serializedName;
    }
    public function getSerializedName() : ?string {
        return $this->serializedName;
    }
    public function setSerializedPath(?PropertyPath $serializedPath = null) : void {
        $this->serializedPath = $serializedPath;
    }
    public function getSerializedPath() : ?PropertyPath {
        return $this->serializedPath;
    }
    public function setIgnore(bool $ignore) : void {
        $this->ignore = $ignore;
    }
    public function isIgnored() : bool {
        return $this->ignore;
    }
    public function getNormalizationContexts() : array {
        return $this->normalizationContexts;
    }
    public function getNormalizationContextForGroups(array $groups) : array {
        $contexts = [];
        foreach ($groups as $group) {
            $contexts[] = $this->normalizationContexts[$group] ?? [];
        }
        return array_merge($this->normalizationContexts['*'] ?? [], ...$contexts);
    }
    public function setNormalizationContextForGroups(array $context, array $groups = []) : void {
        if (!$groups) {
            $this->normalizationContexts['*'] = $context;
        }
        foreach ($groups as $group) {
            $this->normalizationContexts[$group] = $context;
        }
    }
    public function getDenormalizationContexts() : array {
        return $this->denormalizationContexts;
    }
    public function getDenormalizationContextForGroups(array $groups) : array {
        $contexts = [];
        foreach ($groups as $group) {
            $contexts[] = $this->denormalizationContexts[$group] ?? [];
        }
        return array_merge($this->denormalizationContexts['*'] ?? [], ...$contexts);
    }
    public function setDenormalizationContextForGroups(array $context, array $groups = []) : void {
        if (!$groups) {
            $this->denormalizationContexts['*'] = $context;
        }
        foreach ($groups as $group) {
            $this->denormalizationContexts[$group] = $context;
        }
    }
    public function merge(AttributeMetadataInterface $attributeMetadata) : void {
        foreach ($attributeMetadata->getGroups() as $group) {
            $this->addGroup($group);
        }
        // Overwrite only if not defined
        $this->maxDepth ??= $attributeMetadata->getMaxDepth();
        $this->serializedName ??= $attributeMetadata->getSerializedName();
        $this->serializedPath ??= $attributeMetadata->getSerializedPath();
        // Overwrite only if both contexts are empty
        if (!$this->normalizationContexts && !$this->denormalizationContexts) {
            $this->normalizationContexts = $attributeMetadata->getNormalizationContexts();
            $this->denormalizationContexts = $attributeMetadata->getDenormalizationContexts();
        }
        if ($ignore = $attributeMetadata->isIgnored()) {
            $this->ignore = $ignore;
        }
    }
    
    /**
     * Returns the names of the properties that should be serialized.
     *
     * @return string[]
     */
    public function __sleep() : array {
        return [
            'name',
            'groups',
            'maxDepth',
            'serializedName',
            'serializedPath',
            'ignore',
            'normalizationContexts',
            'denormalizationContexts',
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AttributeMetadata::$denormalizationContexts public property @internal This property is public in order to reduce the size of the
class&#039; serialized representation. Do not access it. Use
{@link getDenormalizationContexts()} instead.
AttributeMetadata::$groups public property @internal This property is public in order to reduce the size of the
class&#039; serialized representation. Do not access it. Use
{@link getGroups()} instead.
AttributeMetadata::$ignore public property @internal This property is public in order to reduce the size of the
class&#039; serialized representation. Do not access it. Use
{@link isIgnored()} instead.
AttributeMetadata::$maxDepth public property @internal This property is public in order to reduce the size of the
class&#039; serialized representation. Do not access it. Use
{@link getMaxDepth()} instead.
AttributeMetadata::$name public property @internal This property is public in order to reduce the size of the
class&#039; serialized representation. Do not access it. Use
{@link getName()} instead.
AttributeMetadata::$normalizationContexts public property @internal This property is public in order to reduce the size of the
class&#039; serialized representation. Do not access it. Use
{@link getNormalizationContexts()} instead.
AttributeMetadata::$serializedName public property @internal This property is public in order to reduce the size of the
class&#039; serialized representation. Do not access it. Use
{@link getSerializedName()} instead.
AttributeMetadata::$serializedPath public property @internal This property is public in order to reduce the size of the
class&#039; serialized representation. Do not access it. Use
{@link getSerializedPath()} instead.
AttributeMetadata::addGroup public function Adds this attribute to the given group. Overrides AttributeMetadataInterface::addGroup
AttributeMetadata::getDenormalizationContextForGroups public function Gets the computed denormalization contexts for given groups. Overrides AttributeMetadataInterface::getDenormalizationContextForGroups
AttributeMetadata::getDenormalizationContexts public function Gets all the denormalization contexts per group (&quot;*&quot; being the base context applied to all groups). Overrides AttributeMetadataInterface::getDenormalizationContexts
AttributeMetadata::getGroups public function Gets groups of this attribute. Overrides AttributeMetadataInterface::getGroups
AttributeMetadata::getMaxDepth public function Gets the serialization max depth for this attribute. Overrides AttributeMetadataInterface::getMaxDepth
AttributeMetadata::getName public function Gets the attribute name. Overrides AttributeMetadataInterface::getName
AttributeMetadata::getNormalizationContextForGroups public function Gets the computed normalization contexts for given groups. Overrides AttributeMetadataInterface::getNormalizationContextForGroups
AttributeMetadata::getNormalizationContexts public function Gets all the normalization contexts per group (&quot;*&quot; being the base context applied to all groups). Overrides AttributeMetadataInterface::getNormalizationContexts
AttributeMetadata::getSerializedName public function Gets the serialization name for this attribute. Overrides AttributeMetadataInterface::getSerializedName
AttributeMetadata::getSerializedPath public function Overrides AttributeMetadataInterface::getSerializedPath
AttributeMetadata::isIgnored public function Gets if this attribute is ignored or not. Overrides AttributeMetadataInterface::isIgnored
AttributeMetadata::merge public function Merges an { Overrides AttributeMetadataInterface::merge
AttributeMetadata::setDenormalizationContextForGroups public function Sets the denormalization context for given groups. Overrides AttributeMetadataInterface::setDenormalizationContextForGroups
AttributeMetadata::setIgnore public function Sets if this attribute must be ignored or not. Overrides AttributeMetadataInterface::setIgnore
AttributeMetadata::setMaxDepth public function Sets the serialization max depth for this attribute. Overrides AttributeMetadataInterface::setMaxDepth
AttributeMetadata::setNormalizationContextForGroups public function Sets the normalization context for given groups. Overrides AttributeMetadataInterface::setNormalizationContextForGroups
AttributeMetadata::setSerializedName public function Sets the serialization name for this attribute. Overrides AttributeMetadataInterface::setSerializedName
AttributeMetadata::setSerializedPath public function Overrides AttributeMetadataInterface::setSerializedPath
AttributeMetadata::__construct public function
AttributeMetadata::__sleep public function Returns the names of the properties that should be serialized.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal