FilesLoader.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. /**
  12. * Base loader for loading validation metadata from a list of files.
  13. *
  14. * @author Bulat Shakirzyanov <mallluhuct@gmail.com>
  15. * @author Bernhard Schussek <bschussek@gmail.com>
  16. *
  17. * @see YamlFilesLoader
  18. * @see XmlFilesLoader
  19. */
  20. abstract class FilesLoader extends LoaderChain
  21. {
  22. /**
  23. * Creates a new loader.
  24. *
  25. * @param array $paths An array of file paths
  26. */
  27. public function __construct(array $paths)
  28. {
  29. parent::__construct($this->getFileLoaders($paths));
  30. }
  31. /**
  32. * Returns an array of file loaders for the given file paths.
  33. *
  34. * @return LoaderInterface[] The metadata loaders
  35. */
  36. protected function getFileLoaders(array $paths)
  37. {
  38. $loaders = [];
  39. foreach ($paths as $path) {
  40. $loaders[] = $this->getFileLoaderInstance($path);
  41. }
  42. return $loaders;
  43. }
  44. /**
  45. * Creates a loader for the given file path.
  46. *
  47. * @return LoaderInterface The created loader
  48. */
  49. abstract protected function getFileLoaderInstance(string $path);
  50. }