Drupal investigation

LoaderChain.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\Validator\Mapping\Loader;
  11. use Symfony\Component\Validator\Exception\MappingException;
  12. use Symfony\Component\Validator\Mapping\ClassMetadata;
  13. /**
  14. * Loads validation metadata from multiple {@link LoaderInterface} instances.
  15. *
  16. * Pass the loaders when constructing the chain. Once
  17. * {@link loadClassMetadata()} is called, that method will be called on all
  18. * loaders in the chain.
  19. *
  20. * @author Bernhard Schussek <bschussek@gmail.com>
  21. */
  22. class LoaderChain implements LoaderInterface
  23. {
  24. /**
  25. * @var LoaderInterface[]
  26. */
  27. protected $loaders;
  28. /**
  29. * @param LoaderInterface[] $loaders The metadata loaders to use
  30. *
  31. * @throws MappingException If any of the loaders has an invalid type
  32. */
  33. public function __construct(array $loaders)
  34. {
  35. foreach ($loaders as $loader) {
  36. if (!$loader instanceof LoaderInterface) {
  37. throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', get_class($loader)));
  38. }
  39. }
  40. $this->loaders = $loaders;
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function loadClassMetadata(ClassMetadata $metadata)
  46. {
  47. $success = false;
  48. foreach ($this->loaders as $loader) {
  49. $success = $loader->loadClassMetadata($metadata) || $success;
  50. }
  51. return $success;
  52. }
  53. }