You are here

public function YamlFileLoader::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/YamlFileLoader.php, line 41

Class

YamlFileLoader
Loads validation metadata from a YAML file.

Namespace

Symfony\Component\Validator\Mapping\Loader

Code

public function loadClassMetadata(ClassMetadata $metadata) {
  if (null === $this->classes) {
    if (null === $this->yamlParser) {
      $this->yamlParser = new YamlParser();
    }

    // This method may throw an exception. Do not modify the class'
    // state before it completes
    if (false === ($classes = $this
      ->parseFile($this->file))) {
      return false;
    }
    $this->classes = $classes;
    if (isset($this->classes['namespaces'])) {
      foreach ($this->classes['namespaces'] as $alias => $namespace) {
        $this
          ->addNamespaceAlias($alias, $namespace);
      }
      unset($this->classes['namespaces']);
    }
  }
  if (isset($this->classes[$metadata
    ->getClassName()])) {
    $classDescription = $this->classes[$metadata
      ->getClassName()];
    $this
      ->loadClassMetadataFromYaml($metadata, $classDescription);
    return true;
  }
  return false;
}