You are here

public function XmlFileLoader::loadClassMetadata in Plug 7

Loads validation metadata into a {@link ClassMetadata} instance.

Parameters

ClassMetadata $metadata The metadata to load:

Return value

bool Whether the loader succeeded

Overrides LoaderInterface::loadClassMetadata

File

lib/Symfony/validator/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php, line 35

Class

XmlFileLoader
Loads validation metadata from an XML file.

Namespace

Symfony\Component\Validator\Mapping\Loader

Code

public function loadClassMetadata(ClassMetadata $metadata) {
  if (null === $this->classes) {

    // This method may throw an exception. Do not modify the class'
    // state before it completes
    $xml = $this
      ->parseFile($this->file);
    $this->classes = array();
    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()])) {
    $classDescription = $this->classes[$metadata
      ->getClassName()];
    $this
      ->loadClassMetadataFromXml($metadata, $classDescription);
    return true;
  }
  return false;
}