ClosureLoader.php 919 B

1234567891011121314151617181920212223242526272829303132333435363738
  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\Loader;
  12. use Symfony\Component\Routing\RouteCollection;
  13. /**
  14. * ClosureLoader loads routes from a PHP closure.
  15. *
  16. * The Closure must return a RouteCollection instance.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. class ClosureLoader extends Loader
  21. {
  22. /**
  23. * Loads a Closure.
  24. */
  25. public function load(mixed $closure, ?string $type = null): RouteCollection
  26. {
  27. return $closure($this->env);
  28. }
  29. public function supports(mixed $resource, ?string $type = null): bool
  30. {
  31. return $resource instanceof \Closure && (!$type || 'closure' === $type);
  32. }
  33. }