1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the reva2/jsonapi. |
4
|
|
|
* |
5
|
|
|
* (c) Sergey Revenko <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Reva2\JsonApi\Decoders\Mapping; |
13
|
|
|
|
14
|
|
|
use Reva2\JsonApi\Contracts\Decoders\Mapping\PropertyMetadataInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Property metadata |
18
|
|
|
* |
19
|
|
|
* @package Reva2\JsonApi\Decoders\Mapping |
20
|
|
|
* @author Sergey Revenko <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class PropertyMetadata extends GenericMetadata implements PropertyMetadataInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
* @internal |
27
|
|
|
*/ |
28
|
|
|
public $propertyName; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
* @internal |
33
|
|
|
*/ |
34
|
|
|
public $setter; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
* @internal |
39
|
|
|
*/ |
40
|
|
|
public $dataPath; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
* @internal |
45
|
|
|
*/ |
46
|
|
|
public $dataType; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var mixed |
50
|
|
|
* @internal |
51
|
|
|
*/ |
52
|
|
|
public $dataTypeParams; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var string|null |
56
|
|
|
* @internal |
57
|
|
|
*/ |
58
|
|
|
public $converter; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var array |
62
|
|
|
* @internal |
63
|
|
|
*/ |
64
|
|
|
public $groups = ['Default']; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var array |
68
|
|
|
* @internal |
69
|
|
|
*/ |
70
|
|
|
public $loaders = []; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Constructor |
74
|
|
|
* |
75
|
|
|
* @param string $property |
76
|
|
|
* @param string $className |
77
|
|
|
*/ |
78
|
18 |
|
public function __construct($property, $className) |
79
|
|
|
{ |
80
|
18 |
|
parent::__construct($className); |
81
|
|
|
|
82
|
18 |
|
$this->propertyName = $property; |
83
|
18 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @inheritdoc |
87
|
|
|
*/ |
88
|
16 |
|
public function getPropertyName() |
89
|
|
|
{ |
90
|
16 |
|
return $this->propertyName; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @inheritdoc |
95
|
|
|
*/ |
96
|
11 |
|
public function getSetter() |
97
|
|
|
{ |
98
|
11 |
|
return $this->setter; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Sets property setter |
103
|
|
|
* |
104
|
|
|
* @param string|null $setter |
105
|
|
|
* @return $this |
106
|
|
|
*/ |
107
|
14 |
|
public function setSetter($setter = null) { |
108
|
14 |
|
$this->setter = $setter; |
109
|
|
|
|
110
|
14 |
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
8 |
|
public function getDataPath() |
117
|
|
|
{ |
118
|
8 |
|
return (null !== $this->dataPath) ? $this->dataPath : $this->propertyName; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param string|null $dataPath |
123
|
|
|
* @return $this |
124
|
|
|
*/ |
125
|
17 |
|
public function setDataPath($dataPath = null) |
126
|
|
|
{ |
127
|
17 |
|
$this->dataPath = $dataPath; |
128
|
|
|
|
129
|
17 |
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Returns property data type |
134
|
|
|
* |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
16 |
|
public function getDataType() |
138
|
|
|
{ |
139
|
16 |
|
return $this->dataType; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Sets property data type |
144
|
|
|
* |
145
|
|
|
* @param string $dataType |
146
|
|
|
* @return $this |
147
|
|
|
*/ |
148
|
17 |
|
public function setDataType($dataType) |
149
|
|
|
{ |
150
|
17 |
|
$this->dataType = $dataType; |
151
|
|
|
|
152
|
17 |
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Returns additional data type params |
157
|
|
|
* |
158
|
|
|
* @return mixed |
159
|
|
|
*/ |
160
|
16 |
|
public function getDataTypeParams() |
161
|
|
|
{ |
162
|
16 |
|
return $this->dataTypeParams; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Sets additional data type params |
167
|
|
|
* |
168
|
|
|
* @param mixed $dataTypeParams |
169
|
|
|
* @return $this |
170
|
|
|
*/ |
171
|
17 |
|
public function setDataTypeParams($dataTypeParams = null) |
172
|
|
|
{ |
173
|
17 |
|
$this->dataTypeParams = $dataTypeParams; |
174
|
|
|
|
175
|
17 |
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return string|null |
180
|
|
|
*/ |
181
|
7 |
|
public function getConverter() |
182
|
|
|
{ |
183
|
7 |
|
return $this->converter; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param string|null $converter |
188
|
|
|
* @return $this |
189
|
|
|
*/ |
190
|
17 |
|
public function setConverter($converter) |
191
|
|
|
{ |
192
|
17 |
|
$this->converter = $converter; |
193
|
|
|
|
194
|
17 |
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return array |
199
|
|
|
*/ |
200
|
7 |
|
public function getGroups() |
201
|
|
|
{ |
202
|
7 |
|
return $this->groups; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @param array $groups |
207
|
|
|
* @return $this |
208
|
|
|
*/ |
209
|
17 |
|
public function setGroups(array $groups) |
210
|
|
|
{ |
211
|
17 |
|
$this->groups = $groups; |
212
|
|
|
|
213
|
17 |
|
return $this; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @param array $loaders |
218
|
|
|
* @return $this |
219
|
|
|
*/ |
220
|
17 |
|
public function setLoaders(array $loaders) |
221
|
|
|
{ |
222
|
17 |
|
$this->loaders = $loaders; |
223
|
|
|
|
224
|
17 |
|
return $this; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return array |
229
|
|
|
*/ |
230
|
5 |
|
public function getLoaders() |
231
|
|
|
{ |
232
|
5 |
|
return $this->loaders; |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|