You are here

public function YamlFileLoader::loadClassMetadata in Zircon Profile 8

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

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

vendor/symfony/validator/Mapping/Loader/YamlFileLoader.php, line 42

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;
}