1 | <?php |
||
9 | final class Bind |
||
10 | { |
||
11 | /** |
||
12 | * @var Container |
||
13 | */ |
||
14 | private $container; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | private $interface; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private $name = Name::ANY; |
||
25 | |||
26 | /** |
||
27 | * @var DependencyInterface |
||
28 | */ |
||
29 | private $bound; |
||
30 | |||
31 | /** |
||
32 | * @var BindValidator |
||
33 | */ |
||
34 | private $validate; |
||
35 | |||
36 | /** |
||
37 | * @var null|Untarget |
||
38 | */ |
||
39 | private $untarget; |
||
40 | |||
41 | /** |
||
42 | * @param Container $container dependency container |
||
43 | * @param string $interface interface or concrete class name |
||
44 | */ |
||
45 | public function __construct(Container $container, string $interface) |
||
58 | |||
59 | 92 | public function __destruct() |
|
66 | 43 | ||
67 | public function __toString() |
||
71 | |||
72 | 87 | /** |
|
73 | * Set dependency name |
||
74 | */ |
||
75 | public function annotatedWith(string $name) : self |
||
81 | |||
82 | 31 | /** |
|
83 | * Bind to class |
||
84 | */ |
||
85 | public function to(string $class) : self |
||
94 | |||
95 | 59 | /** |
|
96 | * Bind to constructor |
||
97 | * |
||
98 | * @param string $class class name |
||
99 | * @param string | array $name "varName=bindName,..." or [[$varName => $bindName],[$varName => $bindName]...] |
||
100 | * @param InjectionPoints $injectionPoints injection points |
||
101 | * @param string $postConstruct method name of initialization after all dependencies are injected* |
||
102 | */ |
||
103 | public function toConstructor(string $class, $name, InjectionPoints $injectionPoints = null, string $postConstruct = null) : self |
||
115 | |||
116 | 4 | /** |
|
117 | * Bind to provider |
||
118 | */ |
||
119 | public function toProvider(string $provider, string $context = '') : self |
||
128 | |||
129 | 48 | /** |
|
130 | * Bind to instance |
||
131 | */ |
||
132 | public function toInstance($instance) : self |
||
140 | 80 | ||
141 | 80 | /** |
|
142 | * Set scope |
||
143 | 80 | */ |
|
144 | public function in(string $scope) : self |
||
155 | 41 | ||
156 | public function getBound() : DependencyInterface |
||
160 | |||
161 | 86 | public function setBound(DependencyInterface $bound) |
|
165 | |||
166 | 43 | /** |
|
167 | * @throws \ReflectionException |
||
168 | 43 | */ |
|
169 | 43 | private function getClass(string $class) : \ReflectionClass |
|
177 | |||
178 | private function isRegistered(string $interface) : bool |
||
182 | |||
183 | /** |
||
184 | * Return string |
||
185 | * |
||
186 | 1 | * input: [['varA' => 'nameA'], ['varB' => 'nameB']] |
|
187 | 1 | * output: "varA=nameA,varB=nameB" |
|
188 | */ |
||
189 | 1 | private function getStringName(array $name) : string |
|
199 | } |
||
200 |