public function XmlFileLoader::loadClassMetadata

Load a Class Metadata.

Parameters

ClassMetadata $metadata A metadata:

Return value

Boolean

Overrides LoaderInterface::loadClassMetadata

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php, line 30

Class

XmlFileLoader

Namespace

Symfony\Component\Validator\Mapping\Loader

Code

public function loadClassMetadata(ClassMetadata $metadata) {
  if (null === $this->classes) {
    $this->classes = array();
    $xml = $this
      ->parseFile($this->file);
    foreach ($xml->namespace as $namespace) {
      $this
        ->addNamespaceAlias((string) $namespace['prefix'], trim((string) $namespace));
    }
    foreach ($xml->class as $class) {
      $this->classes[(string) $class['name']] = $class;
    }
  }
  if (isset($this->classes[$metadata
    ->getClassName()])) {
    $xml = $this->classes[$metadata
      ->getClassName()];
    foreach ($xml->{'group-sequence-provider'} as $provider) {
      $metadata
        ->setGroupSequenceProvider(true);
    }
    foreach ($xml->{'group-sequence'} as $groupSequence) {
      if (count($groupSequence->value) > 0) {
        $metadata
          ->setGroupSequence($this
          ->parseValues($groupSequence[0]->value));
      }
    }
    foreach ($this
      ->parseConstraints($xml->constraint) as $constraint) {
      $metadata
        ->addConstraint($constraint);
    }
    foreach ($xml->property as $property) {
      foreach ($this
        ->parseConstraints($property->constraint) as $constraint) {
        $metadata
          ->addPropertyConstraint((string) $property['name'], $constraint);
      }
    }
    foreach ($xml->getter as $getter) {
      foreach ($this
        ->parseConstraints($getter->constraint) as $constraint) {
        $metadata
          ->addGetterConstraint((string) $getter['property'], $constraint);
      }
    }
    return true;
  }
  return false;
}