Mercurial > hg > cmmr2012-drupal-site
comparison vendor/symfony/validator/Mapping/Loader/LoaderChain.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of the Symfony package. | |
5 * | |
6 * (c) Fabien Potencier <fabien@symfony.com> | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Symfony\Component\Validator\Mapping\Loader; | |
13 | |
14 use Symfony\Component\Validator\Exception\MappingException; | |
15 use Symfony\Component\Validator\Mapping\ClassMetadata; | |
16 | |
17 /** | |
18 * Loads validation metadata from multiple {@link LoaderInterface} instances. | |
19 * | |
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. | |
23 * | |
24 * @author Bernhard Schussek <bschussek@gmail.com> | |
25 */ | |
26 class LoaderChain implements LoaderInterface | |
27 { | |
28 protected $loaders; | |
29 | |
30 /** | |
31 * @param LoaderInterface[] $loaders The metadata loaders to use | |
32 * | |
33 * @throws MappingException If any of the loaders has an invalid type | |
34 */ | |
35 public function __construct(array $loaders) | |
36 { | |
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))); | |
40 } | |
41 } | |
42 | |
43 $this->loaders = $loaders; | |
44 } | |
45 | |
46 /** | |
47 * {@inheritdoc} | |
48 */ | |
49 public function loadClassMetadata(ClassMetadata $metadata) | |
50 { | |
51 $success = false; | |
52 | |
53 foreach ($this->loaders as $loader) { | |
54 $success = $loader->loadClassMetadata($metadata) || $success; | |
55 } | |
56 | |
57 return $success; | |
58 } | |
59 | |
60 /** | |
61 * @return LoaderInterface[] | |
62 */ | |
63 public function getLoaders() | |
64 { | |
65 return $this->loaders; | |
66 } | |
67 } |