You are here

class LoaderChain in Plug 7

Loads validation metadata from multiple {@link LoaderInterface} instances.

Pass the loaders when constructing the chain. Once {@link loadClassMetadata()} is called, that method will be called on all loaders in the chain.

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

Expanded class hierarchy of LoaderChain

3 files declare their use of LoaderChain
LazyLoadingMetadataFactory.php in lib/Symfony/validator/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php
LoaderChainTest.php in lib/Symfony/validator/Symfony/Component/Validator/Tests/Mapping/Loader/LoaderChainTest.php
ValidatorBuilder.php in lib/Symfony/validator/Symfony/Component/Validator/ValidatorBuilder.php

File

lib/Symfony/validator/Symfony/Component/Validator/Mapping/Loader/LoaderChain.php, line 26

Namespace

Symfony\Component\Validator\Mapping\Loader
View source
class LoaderChain implements LoaderInterface {

  /**
   * @var LoaderInterface[]
   */
  protected $loaders;

  /**
   * @param LoaderInterface[] $loaders The metadata loaders to use
   *
   * @throws MappingException If any of the loaders has an invalid type
   */
  public function __construct(array $loaders) {
    foreach ($loaders as $loader) {
      if (!$loader instanceof LoaderInterface) {
        throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', get_class($loader)));
      }
    }
    $this->loaders = $loaders;
  }

  /**
   * {@inheritdoc}
   */
  public function loadClassMetadata(ClassMetadata $metadata) {
    $success = false;
    foreach ($this->loaders as $loader) {
      $success = $loader
        ->loadClassMetadata($metadata) || $success;
    }
    return $success;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LoaderChain::$loaders protected property
LoaderChain::loadClassMetadata public function Loads validation metadata into a {@link ClassMetadata} instance. Overrides LoaderInterface::loadClassMetadata
LoaderChain::__construct public function 1