equal
deleted
inserted
replaced
|
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 |
|
16 /** |
|
17 * ClosureLoader loads routes from a PHP closure. |
|
18 * |
|
19 * The Closure must return a RouteCollection instance. |
|
20 * |
|
21 * @author Fabien Potencier <fabien@symfony.com> |
|
22 * |
|
23 * @api |
|
24 */ |
|
25 class ClosureLoader extends Loader |
|
26 { |
|
27 /** |
|
28 * Loads a Closure. |
|
29 * |
|
30 * @param \Closure $closure A Closure |
|
31 * @param string $type The resource type |
|
32 * |
|
33 * @api |
|
34 */ |
|
35 public function load($closure, $type = null) |
|
36 { |
|
37 return call_user_func($closure); |
|
38 } |
|
39 |
|
40 /** |
|
41 * Returns true if this class supports the given resource. |
|
42 * |
|
43 * @param mixed $resource A resource |
|
44 * @param string $type The resource type |
|
45 * |
|
46 * @return Boolean True if this class supports the given resource, false otherwise |
|
47 * |
|
48 * @api |
|
49 */ |
|
50 public function supports($resource, $type = null) |
|
51 { |
|
52 return $resource instanceof \Closure && (!$type || 'closure' === $type); |
|
53 } |
|
54 } |