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
29 * @var LoaderInterface[]
34 * @param LoaderInterface[] $loaders The metadata loaders to use
36 * @throws MappingException If any of the loaders has an invalid type
38 public function __construct(array $loaders)
40 foreach ($loaders as $loader) {
41 if (!$loader instanceof LoaderInterface) {
42 throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', get_class($loader)));
46 $this->loaders = $loaders;
52 public function loadClassMetadata(ClassMetadata $metadata)
56 foreach ($this->loaders as $loader) {
57 $success = $loader->loadClassMetadata($metadata) || $success;