No Description

ClosureLoader.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. * @api
  21. */
  22. class ClosureLoader extends Loader
  23. {
  24. /**
  25. * Loads a Closure.
  26. *
  27. * @param \Closure $closure A Closure
  28. * @param string|null $type The resource type
  29. *
  30. * @return RouteCollection A RouteCollection instance
  31. *
  32. * @api
  33. */
  34. public function load($closure, $type = null)
  35. {
  36. return $closure();
  37. }
  38. /**
  39. * {@inheritdoc}
  40. *
  41. * @api
  42. */
  43. public function supports($resource, $type = null)
  44. {
  45. return $resource instanceof \Closure && (!$type || 'closure' === $type);
  46. }
  47. }