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

Breadcrumb

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

function XmlFileLoader::loadClassMetadata

Same name in this branch
  1. 11.1.x vendor/symfony/validator/Mapping/Loader/XmlFileLoader.php \Symfony\Component\Validator\Mapping\Loader\XmlFileLoader::loadClassMetadata()

Overrides LoaderInterface::loadClassMetadata

File

vendor/symfony/serializer/Mapping/Loader/XmlFileLoader.php, line 36

Class

XmlFileLoader
Loads XML mapping files.

Namespace

Symfony\Component\Serializer\Mapping\Loader

Code

public function loadClassMetadata(ClassMetadataInterface $classMetadata) : bool {
    if (!($this->classes ??= $this->getClassesFromXml())) {
        return false;
    }
    $attributesMetadata = $classMetadata->getAttributesMetadata();
    if (isset($this->classes[$classMetadata->getName()])) {
        $xml = $this->classes[$classMetadata->getName()];
        foreach ($xml->attribute as $attribute) {
            $attributeName = (string) $attribute['name'];
            if (isset($attributesMetadata[$attributeName])) {
                $attributeMetadata = $attributesMetadata[$attributeName];
            }
            else {
                $attributeMetadata = new AttributeMetadata($attributeName);
                $classMetadata->addAttributeMetadata($attributeMetadata);
            }
            foreach ($attribute->group as $group) {
                $attributeMetadata->addGroup((string) $group);
            }
            if (isset($attribute['max-depth'])) {
                $attributeMetadata->setMaxDepth((int) $attribute['max-depth']);
            }
            if (isset($attribute['serialized-name'])) {
                $attributeMetadata->setSerializedName((string) $attribute['serialized-name']);
            }
            if (isset($attribute['serialized-path'])) {
                try {
                    $attributeMetadata->setSerializedPath(new PropertyPath((string) $attribute['serialized-path']));
                } catch (InvalidPropertyPathException) {
                    throw new MappingException(\sprintf('The "serialized-path" value must be a valid property path for the attribute "%s" of the class "%s".', $attributeName, $classMetadata->getName()));
                }
            }
            if (isset($attribute['ignore'])) {
                $attributeMetadata->setIgnore(XmlUtils::phpize($attribute['ignore']));
            }
            foreach ($attribute->context as $node) {
                $groups = (array) $node->group;
                $context = $this->parseContext($node->entry);
                $attributeMetadata->setNormalizationContextForGroups($context, $groups);
                $attributeMetadata->setDenormalizationContextForGroups($context, $groups);
            }
            foreach ($attribute->normalization_context as $node) {
                $groups = (array) $node->group;
                $context = $this->parseContext($node->entry);
                $attributeMetadata->setNormalizationContextForGroups($context, $groups);
            }
            foreach ($attribute->denormalization_context as $node) {
                $groups = (array) $node->group;
                $context = $this->parseContext($node->entry);
                $attributeMetadata->setDenormalizationContextForGroups($context, $groups);
            }
        }
        if (isset($xml->{'discriminator-map'})) {
            $mapping = [];
            foreach ($xml->{'discriminator-map'}->mapping as $element) {
                $elementAttributes = $element->attributes();
                $mapping[(string) $elementAttributes->type] = (string) $elementAttributes->class;
            }
            $classMetadata->setClassDiscriminatorMapping(new ClassDiscriminatorMapping((string) $xml->{'discriminator-map'}
                ->attributes()->{'type-property'}, $mapping));
        }
        return true;
    }
    return false;
}

API Navigation

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