1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Component\Attribute\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
16
|
|
|
* @author Mateusz Zalewski <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class AttributeValue implements AttributeValueInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var mixed |
22
|
|
|
*/ |
23
|
|
|
protected $id; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var AttributeSubjectInterface |
27
|
|
|
*/ |
28
|
|
|
protected $subject; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var AttributeInterface |
32
|
|
|
*/ |
33
|
|
|
protected $attribute; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var mixed |
37
|
|
|
*/ |
38
|
|
|
protected $value; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $text; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var bool |
47
|
|
|
*/ |
48
|
|
|
protected $boolean; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var int |
52
|
|
|
*/ |
53
|
|
|
protected $integer; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var float |
57
|
|
|
*/ |
58
|
|
|
protected $float; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var \DateTime |
62
|
|
|
*/ |
63
|
|
|
protected $datetime; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var \DateTime |
67
|
|
|
*/ |
68
|
|
|
protected $date; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function getId() |
74
|
|
|
{ |
75
|
|
|
return $this->id; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
public function getSubject() |
82
|
|
|
{ |
83
|
|
|
return $this->subject; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function setSubject(AttributeSubjectInterface $subject = null) |
90
|
|
|
{ |
91
|
|
|
$this->subject = $subject; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function getAttribute() |
98
|
|
|
{ |
99
|
|
|
return $this->attribute; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
|
|
public function setAttribute(AttributeInterface $attribute) |
106
|
|
|
{ |
107
|
|
|
$this->attribute = $attribute; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* {@inheritdoc} |
112
|
|
|
*/ |
113
|
|
|
public function getValue() |
114
|
|
|
{ |
115
|
|
|
if (null === $this->attribute) { |
116
|
|
|
return null; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$getter = 'get'.ucfirst($this->attribute->getStorageType()); |
120
|
|
|
|
121
|
|
|
return $this->$getter(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* {@inheritdoc} |
126
|
|
|
*/ |
127
|
|
|
public function setValue($value) |
128
|
|
|
{ |
129
|
|
|
$this->assertAttributeIsSet(); |
130
|
|
|
|
131
|
|
|
$property = $this->attribute->getStorageType(); |
132
|
|
|
$this->$property = $value; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* {@inheritdoc} |
137
|
|
|
*/ |
138
|
|
|
public function getName() |
139
|
|
|
{ |
140
|
|
|
$this->assertAttributeIsSet(); |
141
|
|
|
|
142
|
|
|
return $this->attribute->getName(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* {@inheritdoc} |
147
|
|
|
*/ |
148
|
|
|
public function getType() |
149
|
|
|
{ |
150
|
|
|
$this->assertAttributeIsSet(); |
151
|
|
|
|
152
|
|
|
return $this->attribute->getType(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return boolean |
157
|
|
|
*/ |
158
|
|
|
public function getBoolean() |
159
|
|
|
{ |
160
|
|
|
return $this->boolean; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param boolean $boolean |
165
|
|
|
*/ |
166
|
|
|
public function setBoolean($boolean) |
167
|
|
|
{ |
168
|
|
|
$this->boolean = $boolean; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
public function getText() |
175
|
|
|
{ |
176
|
|
|
return $this->text; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param string $text |
181
|
|
|
*/ |
182
|
|
|
public function setText($text) |
183
|
|
|
{ |
184
|
|
|
$this->text = $text; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return int |
189
|
|
|
*/ |
190
|
|
|
public function getInteger() |
191
|
|
|
{ |
192
|
|
|
return $this->integer; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param int $integer |
197
|
|
|
*/ |
198
|
|
|
public function setInteger($integer) |
199
|
|
|
{ |
200
|
|
|
$this->integer = $integer; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @return float |
205
|
|
|
*/ |
206
|
|
|
public function getFloat() |
207
|
|
|
{ |
208
|
|
|
return $this->float; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @param float $float |
213
|
|
|
*/ |
214
|
|
|
public function setFloat($float) |
215
|
|
|
{ |
216
|
|
|
$this->float = $float; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return \DateTime |
221
|
|
|
*/ |
222
|
|
|
public function getDatetime() |
223
|
|
|
{ |
224
|
|
|
return $this->datetime; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @param \DateTime $datetime |
229
|
|
|
*/ |
230
|
|
|
public function setDatetime(\DateTime $datetime) |
231
|
|
|
{ |
232
|
|
|
$this->datetime = $datetime; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @return \DateTime |
237
|
|
|
*/ |
238
|
|
|
public function getDate() |
239
|
|
|
{ |
240
|
|
|
return $this->date; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @param \DateTime $date |
245
|
|
|
*/ |
246
|
|
|
public function setDate(\DateTime $date) |
247
|
|
|
{ |
248
|
|
|
$this->date = $date; |
249
|
|
|
} |
250
|
|
|
/** |
251
|
|
|
* @throws \BadMethodCallException |
252
|
|
|
*/ |
253
|
|
|
protected function assertAttributeIsSet() |
254
|
|
|
{ |
255
|
|
|
if (null === $this->attribute) { |
256
|
|
|
throw new \BadMethodCallException('The attribute is undefined, so you cannot access proxy methods.'); |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
|