1 | <?php declare(strict_types=1); |
||
11 | class Definition implements ArgumentResolverInterface, DefinitionInterface |
||
12 | { |
||
13 | use ArgumentResolverTrait; |
||
14 | use ContainerAwareTrait; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $alias; |
||
20 | |||
21 | /** |
||
22 | * @var mixed |
||
23 | */ |
||
24 | protected $concrete; |
||
25 | |||
26 | /** |
||
27 | * @var boolean |
||
28 | */ |
||
29 | protected $shared = false; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $tags = []; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $arguments = []; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $methods = []; |
||
45 | |||
46 | /** |
||
47 | * @var mixed |
||
48 | */ |
||
49 | protected $resolved; |
||
50 | |||
51 | /** |
||
52 | * Constructor. |
||
53 | * |
||
54 | * @param string $id |
||
55 | * @param mixed $concrete |
||
56 | */ |
||
57 | 69 | public function __construct(string $id, $concrete = null) |
|
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | 6 | public function addTag(string $tag) : DefinitionInterface |
|
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | 6 | public function hasTag(string $tag) : bool |
|
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | 36 | public function setAlias(string $id) : DefinitionInterface |
|
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | 33 | public function getAlias() : string |
|
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | 39 | public function setShared(bool $shared = true) : DefinitionInterface |
|
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | 45 | public function isShared() : bool |
|
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | 6 | public function getConcrete() |
|
126 | |||
127 | /** |
||
128 | * {@inheritdoc} |
||
129 | */ |
||
130 | 3 | public function setConcrete($concrete) : DefinitionInterface |
|
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | 15 | public function addArgument($arg) : DefinitionInterface |
|
141 | { |
||
142 | 15 | $this->arguments[] = $arg; |
|
143 | |||
144 | 15 | return $this; |
|
145 | } |
||
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | 3 | public function addArguments(array $args) : DefinitionInterface |
|
151 | { |
||
152 | 3 | foreach ($args as $arg) { |
|
153 | 3 | $this->addArgument($arg); |
|
154 | } |
||
155 | |||
156 | 3 | return $this; |
|
157 | } |
||
158 | |||
159 | /** |
||
160 | * {@inheritdoc} |
||
161 | */ |
||
162 | 3 | public function addMethodCall(string $method, array $args = []) : DefinitionInterface |
|
163 | { |
||
164 | 3 | $this->methods[] = [ |
|
165 | 3 | 'method' => $method, |
|
166 | 3 | 'arguments' => $args |
|
167 | ]; |
||
168 | |||
169 | 3 | return $this; |
|
170 | } |
||
171 | |||
172 | /** |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | 3 | public function addMethodCalls(array $methods = []) : DefinitionInterface |
|
183 | |||
184 | /** |
||
185 | * {@inheritdoc} |
||
186 | */ |
||
187 | 45 | public function resolve(bool $new = false) |
|
221 | |||
222 | /** |
||
223 | * Resolve a callable. |
||
224 | * |
||
225 | * @param callable $concrete |
||
226 | * |
||
227 | * @return mixed |
||
228 | */ |
||
229 | 12 | protected function resolveCallable(callable $concrete) |
|
235 | |||
236 | /** |
||
237 | * Resolve a class. |
||
238 | * |
||
239 | * @param string $concrete |
||
240 | * |
||
241 | * @return object |
||
242 | */ |
||
243 | 33 | protected function resolveClass(string $concrete) |
|
250 | |||
251 | /** |
||
252 | * Invoke methods on resolved instance. |
||
253 | * |
||
254 | * @param object $instance |
||
255 | * |
||
256 | * @return object |
||
257 | */ |
||
258 | 39 | protected function invokeMethods($instance) |
|
267 | } |
||
268 |