FilesLoader.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. * @param array $paths An array of file paths
  35. *
  36. * @return LoaderInterface[] The metadata loaders
  37. */
  38. protected function getFileLoaders($paths)
  39. {
  40. $loaders = array();
  41. foreach ($paths as $path) {
  42. $loaders[] = $this->getFileLoaderInstance($path);
  43. }
  44. return $loaders;
  45. }
  46. /**
  47. * Creates a loader for the given file path.
  48. *
  49. * @param string $path The file path
  50. *
  51. * @return LoaderInterface The created loader
  52. */
  53. abstract protected function getFileLoaderInstance($path);
  54. }