菜谱项目

DirectoryLoader.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Routing\RouteCollection;
  13. use Symfony\Component\Config\Resource\DirectoryResource;
  14. class DirectoryLoader extends FileLoader
  15. {
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public function load($file, $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, $type = null)
  43. {
  44. // only when type is forced to directory, not to conflict with AnnotationLoader
  45. return 'directory' === $type;
  46. }
  47. }