GlobFileLoader.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /**
  14. * GlobFileLoader loads files from a glob pattern.
  15. *
  16. * @author Nicolas Grekas <p@tchwork.com>
  17. */
  18. class GlobFileLoader extends FileLoader
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function load($resource, string $type = null)
  24. {
  25. $collection = new RouteCollection();
  26. foreach ($this->glob($resource, false, $globResource) as $path => $info) {
  27. $collection->addCollection($this->import($path));
  28. }
  29. $collection->addResource($globResource);
  30. return $collection;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function supports($resource, string $type = null)
  36. {
  37. return 'glob' === $type;
  38. }
  39. }