1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mapado\RestClientSdk\Mapping; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Attribute |
7
|
|
|
* |
8
|
|
|
* @author Julien Deniau <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
class Attribute |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
private $serializedKey; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $type; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
private $isIdentifier; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $attributeName; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor. |
34
|
|
|
* |
35
|
|
|
* @param string $serializedKey |
36
|
|
|
* @param string|null $attributeName |
37
|
|
|
* @param string $type |
38
|
|
|
* @param bool $isIdentifier |
39
|
|
|
* |
40
|
|
|
* @throws \InvalidArgumentException |
41
|
|
|
*/ |
42
|
|
|
public function __construct( |
43
|
|
|
$serializedKey, |
44
|
|
|
$attributeName = null, |
45
|
|
|
$type = 'string', |
46
|
|
|
$isIdentifier = false |
47
|
|
|
) { |
48
|
|
|
if (empty($serializedKey)) { |
49
|
|
|
throw new \InvalidArgumentException('attribute name must be set'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$this->serializedKey = $serializedKey; |
53
|
|
|
$this->attributeName = $attributeName ?: $this->serializedKey; |
54
|
|
|
$this->type = $type; |
55
|
|
|
$this->isIdentifier = $isIdentifier; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Getter for serializedKey |
60
|
|
|
* |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getSerializedKey() |
64
|
|
|
{ |
65
|
|
|
return $this->serializedKey; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Setter for serializedKey |
70
|
|
|
* |
71
|
|
|
* @param string $serializedKey |
72
|
|
|
* |
73
|
|
|
* @return Attribute |
74
|
|
|
*/ |
75
|
|
|
public function setSerializedKey($serializedKey) |
76
|
|
|
{ |
77
|
|
|
$this->serializedKey = $serializedKey; |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Getter for type |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getType() |
88
|
|
|
{ |
89
|
|
|
return $this->type; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Setter for type |
94
|
|
|
* |
95
|
|
|
* @param string $type |
96
|
|
|
* |
97
|
|
|
* @return Attribute |
98
|
|
|
*/ |
99
|
|
|
public function setType($type) |
100
|
|
|
{ |
101
|
|
|
$this->type = $type; |
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Getter for isIdentifier |
108
|
|
|
* |
109
|
|
|
* @return bool |
110
|
|
|
*/ |
111
|
|
|
public function isIdentifier() |
112
|
|
|
{ |
113
|
|
|
return $this->isIdentifier; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Setter for isIdentifier |
118
|
|
|
* |
119
|
|
|
* @param bool $isIdentifier |
120
|
|
|
* |
121
|
|
|
* @return Attribute |
122
|
|
|
*/ |
123
|
|
|
public function setIsIdentifier($isIdentifier) |
124
|
|
|
{ |
125
|
|
|
$this->isIdentifier = $isIdentifier; |
126
|
|
|
|
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Getter for attributeName |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function getAttributeName() |
136
|
|
|
{ |
137
|
|
|
return $this->attributeName; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Setter for attributeName |
142
|
|
|
* |
143
|
|
|
* @param string $attributeName |
144
|
|
|
* |
145
|
|
|
* @return Attribute |
146
|
|
|
*/ |
147
|
|
|
public function setAttributeName($attributeName) |
148
|
|
|
{ |
149
|
|
|
$this->attributeName = $attributeName; |
150
|
|
|
|
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|