Debian Codegraph @

lib/3rdParty/composer/symfony/serializer/Mapping/Loader/LoaderChain.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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\Serializer\Mapping\Loader;
13
14 use Symfony\Component\Serializer\Exception\MappingException;
15 use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
16
17 /**
18 * Calls multiple {@link LoaderInterface} instances in a chain.
19 *
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
23 * successful or not.
24 *
25 * @author Bernhard Schussek <[email protected]>
26 * @author Kévin Dunglas <[email protected]>
27 */
28 class LoaderChain implements LoaderInterface
29 {
30 /**
31 * Accepts a list of LoaderInterface instances.
32 *
33 * @param LoaderInterface[] $loaders An array of LoaderInterface instances
34 *
35 * @throws MappingException If any of the loaders does not implement LoaderInterface
36 */
37 public function __construct(private readonly array $loaders)
38 {
39 foreach ($loaders as $loader) {
40 if (!$loader instanceof LoaderInterface) {
41 throw new MappingException(\sprintf('Class "%s" is expected to implement LoaderInterface.', get_debug_type($loader)));
42 }
43 }
44 }
45
46 public function loadClassMetadata(ClassMetadataInterface $metadata): bool
47 {
48 $success = false;
49
50 foreach ($this->loaders as $loader) {
51 $success = $loader->loadClassMetadata($metadata) || $success;
52 }
53
54 return $success;
55 }
56
57 /**
58 * @return LoaderInterface[]
59 */
60 public function getLoaders(): array
61 {
62 return $this->loaders;
63 }
64 }