Drupal investigation

ClosureLoader.php 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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, $type = null)
  31. {
  32. return $closure();
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function supports($resource, $type = null)
  38. {
  39. return $resource instanceof \Closure && (!$type || 'closure' === $type);
  40. }
  41. }