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
|
|
|
* Constructor |
62
|
|
|
* |
63
|
|
|
* @param string $property |
64
|
|
|
* @param string $className |
65
|
|
|
*/ |
66
|
17 |
|
public function __construct($property, $className) |
67
|
|
|
{ |
68
|
17 |
|
parent::__construct($className); |
69
|
|
|
|
70
|
17 |
|
$this->propertyName = $property; |
71
|
17 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @inheritdoc |
75
|
|
|
*/ |
76
|
15 |
|
public function getPropertyName() |
77
|
|
|
{ |
78
|
15 |
|
return $this->propertyName; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritdoc |
83
|
|
|
*/ |
84
|
9 |
|
public function getSetter() |
85
|
|
|
{ |
86
|
9 |
|
return $this->setter; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Sets property setter |
91
|
|
|
* |
92
|
|
|
* @param string|null $setter |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
8 |
|
public function setSetter($setter = null) { |
96
|
8 |
|
$this->setter = $setter; |
97
|
|
|
|
98
|
8 |
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
8 |
|
public function getDataPath() |
105
|
|
|
{ |
106
|
8 |
|
return (null !== $this->dataPath) ? $this->dataPath : $this->propertyName; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param string|null $dataPath |
111
|
|
|
* @return $this |
112
|
|
|
*/ |
113
|
16 |
|
public function setDataPath($dataPath = null) |
114
|
|
|
{ |
115
|
16 |
|
$this->dataPath = $dataPath; |
116
|
|
|
|
117
|
16 |
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns property data type |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
15 |
|
public function getDataType() |
126
|
|
|
{ |
127
|
15 |
|
return $this->dataType; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Sets property data type |
132
|
|
|
* |
133
|
|
|
* @param string $dataType |
134
|
|
|
* @return $this |
135
|
|
|
*/ |
136
|
16 |
|
public function setDataType($dataType) |
137
|
|
|
{ |
138
|
16 |
|
$this->dataType = $dataType; |
139
|
|
|
|
140
|
16 |
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Returns additional data type params |
145
|
|
|
* |
146
|
|
|
* @return mixed |
147
|
|
|
*/ |
148
|
15 |
|
public function getDataTypeParams() |
149
|
|
|
{ |
150
|
15 |
|
return $this->dataTypeParams; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Sets additional data type params |
155
|
|
|
* |
156
|
|
|
* @param mixed $dataTypeParams |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
16 |
|
public function setDataTypeParams($dataTypeParams = null) |
160
|
|
|
{ |
161
|
16 |
|
$this->dataTypeParams = $dataTypeParams; |
162
|
|
|
|
163
|
16 |
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return string|null |
168
|
|
|
*/ |
169
|
7 |
|
public function getConverter() |
170
|
|
|
{ |
171
|
7 |
|
return $this->converter; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param string|null $converter |
176
|
|
|
* @return $this |
177
|
|
|
*/ |
178
|
16 |
|
public function setConverter($converter) |
179
|
|
|
{ |
180
|
16 |
|
$this->converter = $converter; |
181
|
|
|
|
182
|
16 |
|
return $this; |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|