Drupal investigation

LoaderChain.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Serializer\Mapping\Loader;
  11. use Symfony\Component\Serializer\Exception\MappingException;
  12. use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
  13. /**
  14. * Calls multiple {@link LoaderInterface} instances in a chain.
  15. *
  16. * This class accepts multiple instances of LoaderInterface to be passed to the
  17. * constructor. When {@link loadClassMetadata()} is called, the same method is called
  18. * in <em>all</em> of these loaders, regardless of whether any of them was
  19. * successful or not.
  20. *
  21. * @author Bernhard Schussek <bschussek@gmail.com>
  22. * @author Kévin Dunglas <dunglas@gmail.com>
  23. */
  24. class LoaderChain implements LoaderInterface
  25. {
  26. /**
  27. * @var LoaderInterface[]
  28. */
  29. private $loaders;
  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(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_class($loader)));
  42. }
  43. }
  44. $this->loaders = $loaders;
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function loadClassMetadata(ClassMetadataInterface $metadata)
  50. {
  51. $success = false;
  52. foreach ($this->loaders as $loader) {
  53. $success = $loader->loadClassMetadata($metadata) || $success;
  54. }
  55. return $success;
  56. }
  57. }