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\Serializer\Mapping\Loader;
14 use Symfony\Component\Serializer\Exception\MappingException;
15 use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
18 * Calls multiple {@link LoaderInterface} instances in a chain.
20 * This class accepts multiple instances of LoaderInterface to be passed to the
21 * constructor. When {@link loadClassMetadata()} is called, the same method is called
22 * in <em>all</em> of these loaders, regardless of whether any of them was
25 * @author Bernhard Schussek <bschussek@gmail.com>
26 * @author Kévin Dunglas <dunglas@gmail.com>
28 class LoaderChain implements LoaderInterface
31 * @var LoaderInterface[]
36 * Accepts a list of LoaderInterface instances.
38 * @param LoaderInterface[] $loaders An array of LoaderInterface instances
40 * @throws MappingException If any of the loaders does not implement LoaderInterface
42 public function __construct(array $loaders)
44 foreach ($loaders as $loader) {
45 if (!$loader instanceof LoaderInterface) {
46 throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', get_class($loader)));
50 $this->loaders = $loaders;
56 public function loadClassMetadata(ClassMetadataInterface $metadata)
60 foreach ($this->loaders as $loader) {
61 $success = $loader->loadClassMetadata($metadata) || $success;