diff options
Diffstat (limited to 'vendor/symfony/routing/Symfony/Component/Routing/Loader/ClosureLoader.php')
-rw-r--r-- | vendor/symfony/routing/Symfony/Component/Routing/Loader/ClosureLoader.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Loader/ClosureLoader.php b/vendor/symfony/routing/Symfony/Component/Routing/Loader/ClosureLoader.php new file mode 100644 index 00000000..8212c291 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Loader/ClosureLoader.php | |||
@@ -0,0 +1,52 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Routing\Loader; | ||
13 | |||
14 | use Symfony\Component\Config\Loader\Loader; | ||
15 | use Symfony\Component\Routing\RouteCollection; | ||
16 | |||
17 | /** | ||
18 | * ClosureLoader loads routes from a PHP closure. | ||
19 | * | ||
20 | * The Closure must return a RouteCollection instance. | ||
21 | * | ||
22 | * @author Fabien Potencier <fabien@symfony.com> | ||
23 | * | ||
24 | * @api | ||
25 | */ | ||
26 | class ClosureLoader extends Loader | ||
27 | { | ||
28 | /** | ||
29 | * Loads a Closure. | ||
30 | * | ||
31 | * @param \Closure $closure A Closure | ||
32 | * @param string|null $type The resource type | ||
33 | * | ||
34 | * @return RouteCollection A RouteCollection instance | ||
35 | * | ||
36 | * @api | ||
37 | */ | ||
38 | public function load($closure, $type = null) | ||
39 | { | ||
40 | return call_user_func($closure); | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * {@inheritdoc} | ||
45 | * | ||
46 | * @api | ||
47 | */ | ||
48 | public function supports($resource, $type = null) | ||
49 | { | ||
50 | return $resource instanceof \Closure && (!$type || 'closure' === $type); | ||
51 | } | ||
52 | } | ||