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.

46 lines
1.1 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\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. * @param \Closure $closure A Closure
  26. * @param string|null $type The resource type
  27. *
  28. * @return RouteCollection A RouteCollection instance
  29. */
  30. public function load($closure, string $type = null)
  31. {
  32. return $closure($this->env);
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function supports($resource, string $type = null)
  38. {
  39. return $resource instanceof \Closure && (!$type || 'closure' === $type);
  40. }
  41. }