1 | <?php |
||
7 | class InjectorConfig |
||
8 | { |
||
9 | /** |
||
10 | * Create a new config instance |
||
11 | * |
||
12 | * @return static |
||
13 | */ |
||
14 | 3 | public static function make(Injector $injector = null) |
|
18 | |||
19 | /** |
||
20 | * @var Injector |
||
21 | */ |
||
22 | private $injector; |
||
23 | |||
24 | 3 | public function __construct(Injector $injector = null) |
|
25 | { |
||
26 | 3 | if (null === $injector) { |
|
27 | 1 | $injector = new Injector(); |
|
28 | 1 | } |
|
29 | |||
30 | 3 | $this->injector = $injector; |
|
31 | 3 | } |
|
32 | |||
33 | /** |
||
34 | * Apply a configuration to the injector |
||
35 | * |
||
36 | * The configuration must either be callable, or be a class name that refers |
||
37 | * to a callable class. |
||
38 | * |
||
39 | * @param callable|string $config |
||
40 | * |
||
41 | * @return self |
||
42 | */ |
||
43 | 2 | public function apply($config) |
|
44 | { |
||
45 | 2 | if (false === is_callable($config)) { |
|
46 | 2 | $config = $this->injector->make($config); |
|
47 | 2 | } |
|
48 | |||
49 | 2 | $config($this->injector); |
|
50 | |||
51 | 2 | return $this; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Apply a list of configurations to the injector |
||
56 | * |
||
57 | * @param array $configs |
||
58 | * |
||
59 | * @return self |
||
60 | */ |
||
61 | 1 | public function configure(array $configs) |
|
67 | |||
68 | /** |
||
69 | * Fetch the injector |
||
70 | * |
||
71 | * @return Injector |
||
72 | */ |
||
73 | 1 | public function injector() |
|
77 | } |
||
78 |