|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by Ruslan Molodyko. |
|
4
|
|
|
* Date: 10.09.2016 |
|
5
|
|
|
* Time: 15:33 |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace samsonframework\container\definition\analyzer\annotation\annotation; |
|
8
|
|
|
|
|
9
|
|
|
use samsonframework\container\definition\analyzer\annotation\ResolveMethodInterface; |
|
10
|
|
|
use samsonframework\container\definition\analyzer\annotation\ResolvePropertyInterface; |
|
11
|
|
|
use samsonframework\container\definition\analyzer\DefinitionAnalyzer; |
|
12
|
|
|
use samsonframework\container\definition\analyzer\exception\WrongAnnotationConstructorException; |
|
13
|
|
|
use samsonframework\container\definition\ClassDefinition; |
|
14
|
|
|
use samsonframework\container\definition\MethodDefinition; |
|
15
|
|
|
use samsonframework\container\definition\PropertyDefinition; |
|
16
|
|
|
use samsonframework\container\definition\reference\ClassReference; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Injection annotation class. |
|
20
|
|
|
* |
|
21
|
|
|
* @Annotation |
|
22
|
|
|
*/ |
|
23
|
|
|
class InjectClass implements ResolvePropertyInterface, ResolveMethodInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var mixed */ |
|
26
|
|
|
protected $value; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Inject constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param $value |
|
32
|
|
|
*/ |
|
33
|
2 |
|
public function __construct($value) |
|
34
|
|
|
{ |
|
35
|
2 |
|
$this->value = $value; |
|
36
|
2 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** {@inheritdoc} */ |
|
39
|
2 |
|
public function resolveProperty( |
|
40
|
|
|
DefinitionAnalyzer $analyzer, |
|
41
|
|
|
\ReflectionProperty $reflectionProperty, |
|
42
|
|
|
ClassDefinition $classDefinition, |
|
43
|
|
|
PropertyDefinition $propertyDefinition |
|
44
|
|
|
) { |
|
45
|
2 |
|
$propertyDefinition->defineDependency(new ClassReference($this->value['value'])); |
|
46
|
2 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
* @throws WrongAnnotationConstructorException |
|
51
|
|
|
*/ |
|
52
|
2 |
|
public function resolveMethod( |
|
53
|
|
|
DefinitionAnalyzer $analyzer, |
|
54
|
|
|
\ReflectionMethod $reflectionMethod, |
|
55
|
|
|
ClassDefinition $classDefinition, |
|
56
|
|
|
MethodDefinition $methodDefinition |
|
57
|
|
|
) { |
|
58
|
|
|
// Get parameter key |
|
59
|
2 |
|
$key = array_keys($this->value)[0]; |
|
60
|
|
|
// Add dependency |
|
61
|
2 |
|
$methodDefinition->defineParameter($key)->defineDependency(new ClassReference($this->value[$key]))->end(); |
|
62
|
2 |
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|