GlobFileLoader.php 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. public function load(mixed $resource, ?string $type = null): mixed
  21. {
  22. $collection = new RouteCollection();
  23. foreach ($this->glob($resource, false, $globResource) as $path => $info) {
  24. $collection->addCollection($this->import($path));
  25. }
  26. $collection->addResource($globResource);
  27. return $collection;
  28. }
  29. public function supports(mixed $resource, ?string $type = null): bool
  30. {
  31. return 'glob' === $type;
  32. }
  33. }