ClosureLoader.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 call_user_func($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. }