Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Validator\Mapping\Loader; Chris@0: Chris@0: use Symfony\Component\Validator\Exception\MappingException; Chris@0: use Symfony\Component\Validator\Mapping\ClassMetadata; Chris@0: Chris@0: /** Chris@0: * Loads validation metadata from multiple {@link LoaderInterface} instances. Chris@0: * Chris@0: * Pass the loaders when constructing the chain. Once Chris@0: * {@link loadClassMetadata()} is called, that method will be called on all Chris@0: * loaders in the chain. Chris@0: * Chris@0: * @author Bernhard Schussek Chris@0: */ Chris@0: class LoaderChain implements LoaderInterface Chris@0: { Chris@0: protected $loaders; Chris@0: Chris@0: /** Chris@0: * @param LoaderInterface[] $loaders The metadata loaders to use Chris@0: * Chris@0: * @throws MappingException If any of the loaders has an invalid type Chris@0: */ Chris@0: public function __construct(array $loaders) Chris@0: { Chris@0: foreach ($loaders as $loader) { Chris@0: if (!$loader instanceof LoaderInterface) { Chris@17: throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', \get_class($loader))); Chris@0: } Chris@0: } Chris@0: Chris@0: $this->loaders = $loaders; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function loadClassMetadata(ClassMetadata $metadata) Chris@0: { Chris@0: $success = false; Chris@0: Chris@0: foreach ($this->loaders as $loader) { Chris@0: $success = $loader->loadClassMetadata($metadata) || $success; Chris@0: } Chris@0: Chris@0: return $success; Chris@0: } Chris@14: Chris@14: /** Chris@14: * @return LoaderInterface[] Chris@14: */ Chris@14: public function getLoaders() Chris@14: { Chris@14: return $this->loaders; Chris@14: } Chris@0: }