Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/validator/Mapping/Loader/LoaderChain.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 /** | |
29 * @var LoaderInterface[] | |
30 */ | |
31 protected $loaders; | |
32 | |
33 /** | |
34 * @param LoaderInterface[] $loaders The metadata loaders to use | |
35 * | |
36 * @throws MappingException If any of the loaders has an invalid type | |
37 */ | |
38 public function __construct(array $loaders) | |
39 { | |
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))); | |
43 } | |
44 } | |
45 | |
46 $this->loaders = $loaders; | |
47 } | |
48 | |
49 /** | |
50 * {@inheritdoc} | |
51 */ | |
52 public function loadClassMetadata(ClassMetadata $metadata) | |
53 { | |
54 $success = false; | |
55 | |
56 foreach ($this->loaders as $loader) { | |
57 $success = $loader->loadClassMetadata($metadata) || $success; | |
58 } | |
59 | |
60 return $success; | |
61 } | |
62 } |