1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Serializer package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\Serializer\Context; |
13
|
|
|
|
14
|
|
|
use Ivory\Serializer\Navigator\NavigatorInterface; |
15
|
|
|
use Ivory\Serializer\Visitor\VisitorInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author GeLo <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class Context implements ContextInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var NavigatorInterface |
24
|
|
|
*/ |
25
|
|
|
private $navigator; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var VisitorInterface |
29
|
|
|
*/ |
30
|
|
|
private $visitor; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var int |
34
|
|
|
*/ |
35
|
|
|
private $direction; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
private $maxDepth = false; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string|null |
44
|
|
|
*/ |
45
|
|
|
private $version; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string[] |
49
|
|
|
*/ |
50
|
|
|
private $groups = []; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var \SplStack |
54
|
|
|
*/ |
55
|
|
|
private $dataStack; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var \SplStack |
59
|
|
|
*/ |
60
|
|
|
private $metadataStack; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function getNavigator() |
66
|
|
|
{ |
67
|
|
|
return $this->navigator; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function setNavigator(NavigatorInterface $navigator) |
74
|
|
|
{ |
75
|
|
|
$this->navigator = $navigator; |
76
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
public function getVisitor() |
84
|
|
|
{ |
85
|
|
|
return $this->visitor; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
|
|
public function setVisitor(VisitorInterface $visitor) |
92
|
|
|
{ |
93
|
|
|
$this->visitor = $visitor; |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* {@inheritdoc} |
100
|
|
|
*/ |
101
|
|
|
public function getDirection() |
102
|
|
|
{ |
103
|
|
|
return $this->direction; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
|
|
public function setDirection($direction) |
110
|
|
|
{ |
111
|
|
|
$this->direction = $direction; |
112
|
|
|
|
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return bool |
118
|
|
|
*/ |
119
|
|
|
public function hasMaxDepthEnabled() |
120
|
|
|
{ |
121
|
|
|
return $this->maxDepth; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* {@inheritdoc} |
126
|
|
|
*/ |
127
|
|
|
public function enableMaxDepth($enable = true) |
128
|
|
|
{ |
129
|
|
|
$this->maxDepth = $enable; |
130
|
|
|
|
131
|
|
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* {@inheritdoc} |
136
|
|
|
*/ |
137
|
|
|
public function hasVersion() |
138
|
|
|
{ |
139
|
|
|
return $this->version !== null; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* {@inheritdoc} |
144
|
|
|
*/ |
145
|
|
|
public function getVersion() |
146
|
|
|
{ |
147
|
|
|
return $this->version; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* {@inheritdoc} |
152
|
|
|
*/ |
153
|
|
|
public function setVersion($version) |
154
|
|
|
{ |
155
|
|
|
$this->version = $version; |
156
|
|
|
|
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* {@inheritdoc} |
162
|
|
|
*/ |
163
|
|
|
public function hasGroups() |
164
|
|
|
{ |
165
|
|
|
return !empty($this->groups); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* {@inheritdoc} |
170
|
|
|
*/ |
171
|
|
|
public function getGroups() |
172
|
|
|
{ |
173
|
|
|
return array_values($this->groups); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* {@inheritdoc} |
178
|
|
|
*/ |
179
|
|
|
public function setGroups(array $groups) |
180
|
|
|
{ |
181
|
|
|
$this->groups = []; |
182
|
|
|
$this->addGroups($groups); |
183
|
|
|
|
184
|
|
|
return $this; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* {@inheritdoc} |
189
|
|
|
*/ |
190
|
|
|
public function addGroups(array $groups) |
191
|
|
|
{ |
192
|
|
|
foreach ($groups as $group) { |
193
|
|
|
$this->addGroup($group); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* {@inheritdoc} |
201
|
|
|
*/ |
202
|
|
|
public function hasGroup($group) |
203
|
|
|
{ |
204
|
|
|
return in_array($group, $this->groups, true); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* {@inheritdoc} |
209
|
|
|
*/ |
210
|
|
|
public function addGroup($group) |
211
|
|
|
{ |
212
|
|
|
if (!$this->hasGroup($group)) { |
213
|
|
|
$this->groups[] = $group; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* {@inheritdoc} |
221
|
|
|
*/ |
222
|
|
|
public function removeGroup($group) |
223
|
|
|
{ |
224
|
|
|
unset($this->groups[array_search($group, $this->groups, true)]); |
225
|
|
|
|
226
|
|
|
return $this; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* {@inheritdoc} |
231
|
|
|
*/ |
232
|
|
|
public function getDataStack() |
233
|
|
|
{ |
234
|
|
|
return $this->dataStack; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* {@inheritdoc} |
239
|
|
|
*/ |
240
|
|
|
public function setDataStack(\SplStack $dataStack) |
241
|
|
|
{ |
242
|
|
|
$this->dataStack = $dataStack; |
243
|
|
|
|
244
|
|
|
return $this; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* {@inheritdoc} |
249
|
|
|
*/ |
250
|
|
|
public function getMetadataStack() |
251
|
|
|
{ |
252
|
|
|
return $this->metadataStack; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* {@inheritdoc} |
257
|
|
|
*/ |
258
|
|
|
public function setMetadataStack(\SplStack $metadataStack) |
259
|
|
|
{ |
260
|
|
|
$this->metadataStack = $metadataStack; |
261
|
|
|
|
262
|
|
|
return $this; |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
|