1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace Mapper; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class ClassField |
9
|
|
|
* @package Mapper |
10
|
|
|
*/ |
11
|
|
|
class ClassField { |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $setter; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $name; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $type; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
private $isAssociative = false; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var bool |
35
|
|
|
*/ |
36
|
|
|
private $isSequential = false; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var bool |
40
|
|
|
*/ |
41
|
|
|
private $isClass = false; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var bool |
45
|
|
|
*/ |
46
|
|
|
private $isSimple = false; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $setter |
50
|
|
|
* @param string $name |
51
|
|
|
* @param string $type |
52
|
|
|
*/ |
53
|
10 |
|
public function __construct( |
54
|
|
|
string $setter, |
55
|
|
|
string $name, |
56
|
|
|
string $type = '' |
57
|
|
|
) { |
58
|
10 |
|
$this->setSetter($setter) |
59
|
10 |
|
->setName($name) |
60
|
10 |
|
->setType($type); |
61
|
10 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
8 |
|
public function getSetter(): string { |
67
|
8 |
|
return $this->setter; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $setter |
72
|
|
|
* @return ClassField |
73
|
|
|
*/ |
74
|
10 |
|
public function setSetter(string $setter): ClassField { |
75
|
10 |
|
$this->setter = $setter; |
76
|
|
|
|
77
|
10 |
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
9 |
|
public function getName(): string { |
84
|
9 |
|
return $this->name; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $name |
89
|
|
|
* @return ClassField |
90
|
|
|
*/ |
91
|
10 |
|
public function setName(string $name): ClassField { |
92
|
10 |
|
$this->name = $name; |
93
|
|
|
|
94
|
10 |
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
9 |
|
public function getType(): string { |
101
|
9 |
|
return $this->type; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param string $type |
106
|
|
|
* @return ClassField |
107
|
|
|
*/ |
108
|
10 |
|
public function setType(string $type): ClassField { |
109
|
10 |
|
if ($type) { |
110
|
8 |
|
if (class_exists($type)) { |
111
|
6 |
|
$this->setIsClass(); |
112
|
|
|
|
113
|
6 |
|
if ($type[0] !== '\\') { |
114
|
5 |
|
$type = "\\$type"; |
115
|
|
|
} |
116
|
6 |
|
} elseif ($type === 'array') { |
117
|
1 |
|
$this->setIsAssociative(); |
118
|
|
|
} else { |
119
|
5 |
|
$this->setIsSimple(); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
10 |
|
$this->type = $type; |
124
|
|
|
|
125
|
10 |
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return bool |
130
|
|
|
*/ |
131
|
5 |
|
public function isAssociative(): bool { |
132
|
5 |
|
return $this->isAssociative; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return bool |
137
|
|
|
*/ |
138
|
5 |
|
public function isNotAssociative(): bool { |
139
|
5 |
|
return !$this->isAssociative; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return ClassField |
144
|
|
|
*/ |
145
|
2 |
|
public function setIsAssociative(): ClassField { |
146
|
2 |
|
$this->isAssociative = true; |
147
|
|
|
|
148
|
2 |
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return ClassField |
153
|
|
|
*/ |
154
|
1 |
|
public function setIsNotAssociative(): ClassField { |
155
|
1 |
|
$this->isAssociative = false; |
156
|
|
|
|
157
|
1 |
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return bool |
162
|
|
|
*/ |
163
|
8 |
|
public function isSequential(): bool { |
164
|
8 |
|
return $this->isSequential; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return bool |
169
|
|
|
*/ |
170
|
5 |
|
public function isNotSequential(): bool { |
171
|
5 |
|
return !$this->isSequential; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return ClassField |
176
|
|
|
*/ |
177
|
5 |
|
public function setIsSequential(): ClassField { |
178
|
5 |
|
$this->isSequential = true; |
179
|
|
|
|
180
|
5 |
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return ClassField |
185
|
|
|
*/ |
186
|
1 |
|
public function setIsNotSequential(): ClassField { |
187
|
1 |
|
$this->isSequential = false; |
188
|
|
|
|
189
|
1 |
|
return $this; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @return bool |
194
|
|
|
*/ |
195
|
8 |
|
public function isClass(): bool { |
196
|
8 |
|
return $this->isClass; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return bool |
201
|
|
|
*/ |
202
|
5 |
|
public function isNotClass(): bool { |
203
|
5 |
|
return !$this->isClass; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return ClassField |
208
|
|
|
*/ |
209
|
6 |
|
public function setIsClass(): ClassField { |
210
|
6 |
|
$this->isClass = true; |
211
|
|
|
|
212
|
6 |
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return ClassField |
217
|
|
|
*/ |
218
|
1 |
|
public function setIsNotClass(): ClassField { |
219
|
1 |
|
$this->isClass = false; |
220
|
|
|
|
221
|
1 |
|
return $this; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @return bool |
226
|
|
|
*/ |
227
|
5 |
|
public function isSimple(): bool { |
228
|
5 |
|
return $this->isSimple; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @return bool |
233
|
|
|
*/ |
234
|
5 |
|
public function isNotSimple(): bool { |
235
|
5 |
|
return !$this->isSimple; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @return ClassField |
240
|
|
|
*/ |
241
|
6 |
|
public function setIsSimple(): ClassField { |
242
|
6 |
|
$this->isSimple = true; |
243
|
|
|
|
244
|
6 |
|
return $this; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @return ClassField |
249
|
|
|
*/ |
250
|
1 |
|
public function setIsNotSimple(): ClassField { |
251
|
1 |
|
$this->isSimple = false; |
252
|
|
|
|
253
|
1 |
|
return $this; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
} |