|
0
|
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\DependencyInjection\Loader; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
|
15 |
use Symfony\Component\Config\Loader\Loader; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* ClosureLoader loads service definitions from a PHP closure. |
|
|
19 |
* |
|
|
20 |
* The Closure has access to the container as its first argument. |
|
|
21 |
* |
|
|
22 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
23 |
*/ |
|
|
24 |
class ClosureLoader extends Loader |
|
|
25 |
{ |
|
|
26 |
private $container; |
|
|
27 |
|
|
|
28 |
/** |
|
|
29 |
* Constructor. |
|
|
30 |
* |
|
|
31 |
* @param ContainerBuilder $container A ContainerBuilder instance |
|
|
32 |
*/ |
|
|
33 |
public function __construct(ContainerBuilder $container) |
|
|
34 |
{ |
|
|
35 |
$this->container = $container; |
|
|
36 |
} |
|
|
37 |
|
|
|
38 |
/** |
|
|
39 |
* Loads a Closure. |
|
|
40 |
* |
|
|
41 |
* @param \Closure $closure The resource |
|
|
42 |
* @param string $type The resource type |
|
|
43 |
*/ |
|
|
44 |
public function load($closure, $type = null) |
|
|
45 |
{ |
|
|
46 |
call_user_func($closure, $this->container); |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
/** |
|
|
50 |
* Returns true if this class supports the given resource. |
|
|
51 |
* |
|
|
52 |
* @param mixed $resource A resource |
|
|
53 |
* @param string $type The resource type |
|
|
54 |
* |
|
|
55 |
* @return Boolean true if this class supports the given resource, false otherwise |
|
|
56 |
*/ |
|
|
57 |
public function supports($resource, $type = null) |
|
|
58 |
{ |
|
|
59 |
return $resource instanceof \Closure; |
|
|
60 |
} |
|
|
61 |
} |