1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: root |
5
|
|
|
* Date: 02.08.16 |
6
|
|
|
* Time: 0:46. |
7
|
|
|
*/ |
8
|
|
|
namespace samsonframework\container\definition; |
9
|
|
|
|
10
|
|
|
use samsonframework\container\definition\reference\ReferenceInterface; |
11
|
|
|
use samsonframework\container\exception\ParameterDefinitionAlreadyExistsException; |
12
|
|
|
use samsonframework\container\exception\ReferenceNotImplementsException; |
13
|
|
|
use samsonframework\container\metadata\ClassMetadata; |
14
|
|
|
use samsonframework\container\metadata\MethodMetadata; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class MethodDefinition |
18
|
|
|
* |
19
|
|
|
* @package samsonframework\container\definition |
20
|
|
|
*/ |
21
|
|
|
class MethodDefinition extends AbstractDefinition implements MethodBuilderInterface |
22
|
|
|
{ |
23
|
|
|
/** @var string Method name */ |
24
|
|
|
protected $methodName; |
25
|
|
|
/** @var ParameterDefinition[] Collection of parameter collection */ |
26
|
|
|
protected $parametersCollection = []; |
27
|
|
|
/** @var int Method modifiers */ |
28
|
|
|
public $modifiers = 0; |
29
|
|
|
/** @var bool Flag that method is public */ |
30
|
|
|
public $isPublic = false; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Define arguments |
34
|
|
|
* |
35
|
|
|
* @param string $parameterName |
36
|
|
|
* @return ParameterBuilderInterface |
37
|
|
|
* @throws ParameterDefinitionAlreadyExistsException |
38
|
|
|
*/ |
39
|
2 |
|
public function defineParameter($parameterName): ParameterBuilderInterface |
40
|
|
|
{ |
41
|
2 |
|
if (array_key_exists($parameterName, $this->parametersCollection)) { |
42
|
|
|
throw new ParameterDefinitionAlreadyExistsException(); |
43
|
|
|
} |
44
|
|
|
|
45
|
2 |
|
$parameter = new ParameterDefinition($this); |
46
|
2 |
|
$parameter->setParameterName($parameterName); |
47
|
|
|
|
48
|
2 |
|
$this->parametersCollection[$parameterName] = $parameter; |
49
|
|
|
|
50
|
2 |
|
return $parameter; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Resolve method metadata |
55
|
|
|
* |
56
|
|
|
* @param ClassMetadata $classMetadata |
57
|
|
|
* @return MethodMetadata |
58
|
|
|
* @throws ReferenceNotImplementsException |
59
|
|
|
*/ |
60
|
|
|
public function toMethodMetadata(ClassMetadata $classMetadata): MethodMetadata |
61
|
|
|
{ |
62
|
|
|
$methodMetadata = new MethodMetadata($classMetadata); |
63
|
|
|
$methodMetadata->name = $this->getMethodName(); |
64
|
|
|
|
65
|
|
|
return $methodMetadata; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getMethodName(): string |
72
|
|
|
{ |
73
|
|
|
return $this->methodName; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return boolean |
78
|
|
|
*/ |
79
|
|
|
public function getIsPublic(): bool |
80
|
|
|
{ |
81
|
|
|
return $this->isPublic; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param boolean $isPublic |
86
|
|
|
* @return MethodDefinition |
87
|
|
|
*/ |
88
|
|
|
public function setIsPublic(bool $isPublic): MethodDefinition |
89
|
|
|
{ |
90
|
|
|
$this->isPublic = $isPublic; |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $methodName |
97
|
|
|
* @return MethodDefinition |
98
|
|
|
*/ |
99
|
4 |
|
public function setMethodName(string $methodName): MethodDefinition |
100
|
|
|
{ |
101
|
4 |
|
$this->methodName = $methodName; |
102
|
|
|
|
103
|
4 |
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return int |
108
|
|
|
*/ |
109
|
|
|
public function getModifiers(): int |
110
|
|
|
{ |
111
|
|
|
return $this->modifiers; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param int $modifiers |
116
|
|
|
* @return MethodDefinition |
117
|
|
|
*/ |
118
|
|
|
public function setModifiers(int $modifiers): MethodDefinition |
119
|
|
|
{ |
120
|
|
|
$this->modifiers = $modifiers; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|