4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Mapping\Loader;
14 use Symfony\Component\Validator\Exception\MappingException;
15 use Symfony\Component\Validator\Mapping\ClassMetadata;
18 * Loads validation metadata from multiple {@link LoaderInterface} instances.
20 * Pass the loaders when constructing the chain. Once
21 * {@link loadClassMetadata()} is called, that method will be called on all
22 * loaders in the chain.
24 * @author Bernhard Schussek <bschussek@gmail.com>
26 class LoaderChain implements LoaderInterface
31 * @param LoaderInterface[] $loaders The metadata loaders to use
33 * @throws MappingException If any of the loaders has an invalid type
35 public function __construct(array $loaders)
37 foreach ($loaders as $loader) {
38 if (!$loader instanceof LoaderInterface) {
39 throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', get_class($loader)));
43 $this->loaders = $loaders;
49 public function loadClassMetadata(ClassMetadata $metadata)
53 foreach ($this->loaders as $loader) {
54 $success = $loader->loadClassMetadata($metadata) || $success;
61 * @return LoaderInterface[]
63 public function getLoaders()
65 return $this->loaders;