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 null|string|array |
50
|
|
|
* @internal |
51
|
|
|
*/ |
52
|
|
|
public $dataTypeParams; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Constructor |
56
|
|
|
* |
57
|
|
|
* @param string $property |
58
|
|
|
* @param string $className |
59
|
|
|
*/ |
60
|
13 |
|
public function __construct($property, $className) |
61
|
|
|
{ |
62
|
13 |
|
parent::__construct($className); |
63
|
|
|
|
64
|
13 |
|
$this->propertyName = $property; |
65
|
13 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @inheritdoc |
69
|
|
|
*/ |
70
|
11 |
|
public function getPropertyName() |
71
|
|
|
{ |
72
|
11 |
|
return $this->propertyName; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @inheritdoc |
77
|
|
|
*/ |
78
|
7 |
|
public function getSetter() |
79
|
|
|
{ |
80
|
7 |
|
return $this->setter; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Sets property setter |
85
|
|
|
* |
86
|
|
|
* @param string|null $setter |
87
|
|
|
* @return $this |
88
|
|
|
*/ |
89
|
6 |
|
public function setSetter($setter = null) { |
90
|
6 |
|
$this->setter = $setter; |
91
|
|
|
|
92
|
6 |
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
5 |
|
public function getDataPath() |
99
|
|
|
{ |
100
|
5 |
|
return (null !== $this->dataPath) ? $this->dataPath : $this->propertyName; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param string|null $dataPath |
105
|
|
|
* @return $this |
106
|
|
|
*/ |
107
|
12 |
|
public function setDataPath($dataPath = null) |
108
|
|
|
{ |
109
|
12 |
|
$this->dataPath = $dataPath; |
110
|
|
|
|
111
|
12 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Returns property data type |
116
|
|
|
* |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
11 |
|
public function getDataType() |
120
|
|
|
{ |
121
|
11 |
|
return $this->dataType; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Sets property data type |
126
|
|
|
* |
127
|
|
|
* @param string $dataType |
128
|
|
|
* @return $this |
129
|
|
|
*/ |
130
|
12 |
|
public function setDataType($dataType) |
131
|
|
|
{ |
132
|
12 |
|
$this->dataType = $dataType; |
133
|
|
|
|
134
|
12 |
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Returns additional data type params |
139
|
|
|
* |
140
|
|
|
* @return array|null|string |
141
|
|
|
*/ |
142
|
11 |
|
public function getDataTypeParams() |
143
|
|
|
{ |
144
|
11 |
|
return $this->dataTypeParams; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Sets additional data type params |
149
|
|
|
* |
150
|
|
|
* @param array|null|string $dataTypeParams |
151
|
|
|
* @return $this |
152
|
|
|
*/ |
153
|
12 |
|
public function setDataTypeParams($dataTypeParams = null) |
154
|
|
|
{ |
155
|
12 |
|
$this->dataTypeParams = $dataTypeParams; |
156
|
|
|
|
157
|
12 |
|
return $this; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|