You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

3 years ago
  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\Routing\Loader;
  11. use Symfony\Component\Config\Loader\FileLoader;
  12. use Symfony\Component\Config\Resource\DirectoryResource;
  13. use Symfony\Component\Routing\RouteCollection;
  14. class DirectoryLoader extends FileLoader
  15. {
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public function load($file, string $type = null)
  20. {
  21. $path = $this->locator->locate($file);
  22. $collection = new RouteCollection();
  23. $collection->addResource(new DirectoryResource($path));
  24. foreach (scandir($path) as $dir) {
  25. if ('.' !== $dir[0]) {
  26. $this->setCurrentDir($path);
  27. $subPath = $path.'/'.$dir;
  28. $subType = null;
  29. if (is_dir($subPath)) {
  30. $subPath .= '/';
  31. $subType = 'directory';
  32. }
  33. $subCollection = $this->import($subPath, $subType, false, $path);
  34. $collection->addCollection($subCollection);
  35. }
  36. }
  37. return $collection;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function supports($resource, string $type = null)
  43. {
  44. // only when type is forced to directory, not to conflict with AnnotationLoader
  45. return 'directory' === $type;
  46. }
  47. }