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\exception\MethodDefinitionAlreadyExistsException; |
15
|
|
|
use samsonframework\container\definition\exception\MethodDefinitionNotFoundException; |
16
|
|
|
use samsonframework\container\definition\exception\ParameterDefinitionAlreadyExistsException; |
17
|
|
|
use samsonframework\container\definition\exception\PropertyDefinitionAlreadyExistsException; |
18
|
|
|
use samsonframework\container\definition\exception\PropertyDefinitionNotFoundException; |
19
|
|
|
use samsonframework\container\definition\reference\ClassReference; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Injection annotation class. |
23
|
|
|
* |
24
|
|
|
* @Annotation |
25
|
|
|
*/ |
26
|
|
|
class InjectClass implements ResolvePropertyInterface, ResolveMethodInterface |
27
|
|
|
{ |
28
|
|
|
/** @var mixed */ |
29
|
|
|
protected $value; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Inject constructor. |
33
|
|
|
* |
34
|
|
|
* @param $value |
35
|
|
|
*/ |
36
|
2 |
|
public function __construct($value) |
37
|
|
|
{ |
38
|
2 |
|
$this->value = $value; |
39
|
2 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
* @throws PropertyDefinitionNotFoundException |
44
|
|
|
* @throws PropertyDefinitionAlreadyExistsException |
45
|
|
|
*/ |
46
|
2 |
|
public function resolveProperty( |
47
|
|
|
DefinitionAnalyzer $analyzer, |
48
|
|
|
ClassDefinition $classDefinition, |
49
|
|
|
\ReflectionProperty $reflectionProperty |
50
|
|
|
) { |
51
|
2 |
|
$classDefinition->setupProperty($reflectionProperty->getName()) |
52
|
2 |
|
->defineDependency(new ClassReference($this->value['value'])); |
53
|
2 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
* @throws WrongAnnotationConstructorException |
58
|
|
|
* @throws MethodDefinitionNotFoundException |
59
|
|
|
* @throws ParameterDefinitionAlreadyExistsException |
60
|
|
|
* @throws MethodDefinitionAlreadyExistsException |
61
|
|
|
*/ |
62
|
2 |
|
public function resolveMethod( |
63
|
|
|
DefinitionAnalyzer $analyzer, |
64
|
|
|
ClassDefinition $classDefinition, |
65
|
|
|
\ReflectionMethod $reflectionMethod |
66
|
|
|
) { |
67
|
|
|
// Get parameter key |
68
|
2 |
|
$key = array_keys($this->value)[0]; |
69
|
2 |
|
$classDefinition->setupMethod($reflectionMethod->getName()) |
|
|
|
|
70
|
2 |
|
->defineParameter($key) |
71
|
2 |
|
->defineDependency(new ClassReference($this->value[$key]))->end(); |
72
|
2 |
|
} |
73
|
|
|
} |
74
|
|
|
|