1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is a part of "Axessors" library. |
4
|
|
|
* |
5
|
|
|
* @author <[email protected]> |
6
|
|
|
* @license GPL |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace NoOne4rever\Axessors; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class PropertyData. |
13
|
|
|
* |
14
|
|
|
* Stores information about Axessors property. |
15
|
|
|
* |
16
|
|
|
* @package NoOne4rever\Axessors |
17
|
|
|
*/ |
18
|
|
|
class PropertyData |
19
|
|
|
{ |
20
|
|
|
/** @var \ReflectionProperty property's reflection */ |
21
|
|
|
public $reflection; |
22
|
|
|
|
23
|
|
|
/** @var string[] access modifiers for getter and setter */ |
24
|
|
|
private $accessibility; |
25
|
|
|
/** @var string an alias of property name */ |
26
|
|
|
private $alias; |
27
|
|
|
/** @var array type tree */ |
28
|
|
|
private $type; |
29
|
|
|
/** @var string conditions for setter */ |
30
|
|
|
private $conditionsIn; |
31
|
|
|
/** @var string conditions for getter */ |
32
|
|
|
private $conditionsOut; |
33
|
|
|
/** @var string[] handlers for setter */ |
34
|
|
|
private $handlersIn = []; |
35
|
|
|
/** @var string[] handlers for getter */ |
36
|
|
|
private $handlersOut = []; |
37
|
|
|
/** @var string[] methods' names */ |
38
|
|
|
private $methods = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* PropertyData constructor. |
42
|
|
|
* |
43
|
|
|
* @param \ReflectionProperty $reflection property's information |
44
|
|
|
* @param array $tokens tokens form Axessors comment |
45
|
|
|
*/ |
46
|
5 |
|
public function __construct(\ReflectionProperty $reflection, array $tokens) |
47
|
|
|
{ |
48
|
5 |
|
$parser = new Parser($reflection, $tokens); |
49
|
4 |
|
$this->reflection = $reflection; |
50
|
4 |
|
$this->accessibility = $parser->processAccessModifier(); |
51
|
4 |
|
$this->alias = $parser->getAlias(); |
52
|
4 |
|
$typeProcessor = new TypeProcessor($parser->getReflection(), $parser->getNamespace(), $parser->getTypeDef()); |
53
|
4 |
|
$typeProcessor->processType(); |
54
|
2 |
|
$this->type = $typeProcessor->getTypeTree(); |
55
|
2 |
|
$conditionsProcessor = new ConditionsProcessor($parser->getInConditions(), $parser->getOutConditions(), |
56
|
2 |
|
$parser->getNamespace()); |
57
|
2 |
|
$this->conditionsIn = $conditionsProcessor->processInputData(); |
58
|
2 |
|
$this->conditionsOut = $conditionsProcessor->processOutputData(); |
59
|
2 |
|
$handlersProcessor = new HandlersProcessor($parser->getInHandlers(), $parser->getOutHandlers(), |
60
|
2 |
|
$parser->getNamespace()); |
61
|
2 |
|
$this->handlersIn = $handlersProcessor->processInputData(); |
62
|
2 |
|
$this->handlersOut = $handlersProcessor->processOutputData(); |
63
|
2 |
|
$methodsProcessor = new MethodsProcessor($this->accessibility['write'] ?? '', |
64
|
2 |
|
$this->accessibility['read'] ?? '', $this->getAlias()); |
65
|
2 |
|
$this->methods = $methodsProcessor->processMethods($typeProcessor->getTypeTree()); |
66
|
2 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Getter for {@see PropertyData::$alias}. |
70
|
|
|
* |
71
|
|
|
* @return string {@see PropertyData::$alias} |
72
|
|
|
*/ |
73
|
94 |
|
public function getAlias(): string |
74
|
|
|
{ |
75
|
94 |
|
return $this->alias; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Getter for {@see PropertyData::$methods}. |
80
|
|
|
* |
81
|
|
|
* @return string[] {@see PropertyData::$methods} |
82
|
|
|
*/ |
83
|
104 |
|
public function getMethods(): array |
84
|
|
|
{ |
85
|
104 |
|
return $this->methods; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Getter for {@see PropertyData::$conditionsIn}. |
90
|
|
|
* |
91
|
|
|
* @return string {@see PropertyData::$conditionsIn} |
92
|
|
|
*/ |
93
|
64 |
|
public function getInputConditions(): string |
94
|
|
|
{ |
95
|
64 |
|
return $this->conditionsIn; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Getter for {@see PropertyData::$conditionsOut}. |
100
|
|
|
* |
101
|
|
|
* @return string {@see PropertyData::$conditionsOut} |
102
|
|
|
*/ |
103
|
18 |
|
public function getOutputConditions(): string |
104
|
|
|
{ |
105
|
18 |
|
return $this->conditionsOut; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Getter for {@see PropertyData::$handlersOut}. |
110
|
|
|
* |
111
|
|
|
* @return string[] {@see PropertyData::$handlersOut} |
112
|
|
|
*/ |
113
|
15 |
|
public function getOutputHandlers(): array |
114
|
|
|
{ |
115
|
15 |
|
return $this->handlersOut; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Getter for {@see PropertyData::$handlersIn}. |
120
|
|
|
* |
121
|
|
|
* @return string[] {@see PropertyData::$handlersIn} |
122
|
|
|
*/ |
123
|
47 |
|
public function getInputHandlers(): array |
124
|
|
|
{ |
125
|
47 |
|
return $this->handlersIn; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Getter for {@see PropertyData::$type}. |
130
|
|
|
* |
131
|
|
|
* @return array {@see PropertyData::$type} |
132
|
|
|
*/ |
133
|
91 |
|
public function getTypeTree(): array |
134
|
|
|
{ |
135
|
91 |
|
return $this->type; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Getter for {@see PropertyData::$alias}. |
140
|
|
|
* |
141
|
|
|
* @return string {@see PropertyData::$alias} |
142
|
|
|
*/ |
143
|
8 |
|
public function getName(): string |
144
|
|
|
{ |
145
|
8 |
|
return $this->alias; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|