You are here

public function XmlFileLoader::loadClassMetadata in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/validator/Mapping/Loader/XmlFileLoader.php \Symfony\Component\Validator\Mapping\Loader\XmlFileLoader::loadClassMetadata()
  2. 8 vendor/symfony/serializer/Mapping/Loader/XmlFileLoader.php \Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader::loadClassMetadata()
Same name and namespace in other branches
  1. 8.0 vendor/symfony/serializer/Mapping/Loader/XmlFileLoader.php \Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader::loadClassMetadata()

Load class metadata.

Parameters

ClassMetadataInterface $classMetadata A metadata:

Return value

bool

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) {
  if (null === $this->classes) {
    $this->classes = array();
    $xml = $this
      ->parseFile($this->file);
    foreach ($xml->class as $class) {
      $this->classes[(string) $class['name']] = $class;
    }
  }
  $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);
      }
    }
    return true;
  }
  return false;
}