You are here

class YamlFileLoader in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/routing/Loader/YamlFileLoader.php \Symfony\Component\Routing\Loader\YamlFileLoader
  2. 8 vendor/symfony/translation/Loader/YamlFileLoader.php \Symfony\Component\Translation\Loader\YamlFileLoader
  3. 8 vendor/symfony/dependency-injection/Loader/YamlFileLoader.php \Symfony\Component\DependencyInjection\Loader\YamlFileLoader
  4. 8 vendor/symfony/validator/Mapping/Loader/YamlFileLoader.php \Symfony\Component\Validator\Mapping\Loader\YamlFileLoader
  5. 8 vendor/symfony/serializer/Mapping/Loader/YamlFileLoader.php \Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader
  6. 8 core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php \Drupal\Core\DependencyInjection\YamlFileLoader
Same name and namespace in other branches
  1. 8.0 vendor/symfony/serializer/Mapping/Loader/YamlFileLoader.php \Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader

YAML File Loader.

@author Kévin Dunglas <dunglas@gmail.com>

Hierarchy

Expanded class hierarchy of YamlFileLoader

1 file declares its use of YamlFileLoader
YamlFileLoaderTest.php in vendor/symfony/serializer/Tests/Mapping/Loader/YamlFileLoaderTest.php
1 string reference to 'YamlFileLoader'
TranslatorTest::getTransFileTests in vendor/symfony/translation/Tests/TranslatorTest.php

File

vendor/symfony/serializer/Mapping/Loader/YamlFileLoader.php, line 24

Namespace

Symfony\Component\Serializer\Mapping\Loader
View source
class YamlFileLoader extends FileLoader {
  private $yamlParser;

  /**
   * An array of YAML class descriptions.
   *
   * @var array
   */
  private $classes = null;

  /**
   * {@inheritdoc}
   */
  public function loadClassMetadata(ClassMetadataInterface $classMetadata) {
    if (null === $this->classes) {
      if (!stream_is_local($this->file)) {
        throw new MappingException(sprintf('This is not a local file "%s".', $this->file));
      }
      if (null === $this->yamlParser) {
        $this->yamlParser = new Parser();
      }
      $classes = $this->yamlParser
        ->parse(file_get_contents($this->file));
      if (empty($classes)) {
        return false;
      }

      // not an array
      if (!is_array($classes)) {
        throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file));
      }
      $this->classes = $classes;
    }
    if (isset($this->classes[$classMetadata
      ->getName()])) {
      $yaml = $this->classes[$classMetadata
        ->getName()];
      if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
        $attributesMetadata = $classMetadata
          ->getAttributesMetadata();
        foreach ($yaml['attributes'] as $attribute => $data) {
          if (isset($attributesMetadata[$attribute])) {
            $attributeMetadata = $attributesMetadata[$attribute];
          }
          else {
            $attributeMetadata = new AttributeMetadata($attribute);
            $classMetadata
              ->addAttributeMetadata($attributeMetadata);
          }
          if (isset($data['groups'])) {
            foreach ($data['groups'] as $group) {
              $attributeMetadata
                ->addGroup($group);
            }
          }
        }
      }
      return true;
    }
    return false;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileLoader::$file protected property
FileLoader::__construct public function Constructor.
YamlFileLoader::$classes private property An array of YAML class descriptions.
YamlFileLoader::$yamlParser private property
YamlFileLoader::loadClassMetadata public function Load class metadata. Overrides LoaderInterface::loadClassMetadata