|
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\Exclusion\ExclusionStrategy; |
|
15
|
|
|
use Ivory\Serializer\Exclusion\ExclusionStrategyInterface; |
|
16
|
|
|
use Ivory\Serializer\Mapping\MetadataInterface; |
|
17
|
|
|
use Ivory\Serializer\Naming\IdenticalNamingStrategy; |
|
18
|
|
|
use Ivory\Serializer\Naming\NamingStrategyInterface; |
|
19
|
|
|
use Ivory\Serializer\Navigator\NavigatorInterface; |
|
20
|
|
|
use Ivory\Serializer\Visitor\VisitorInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @author GeLo <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class Context implements ContextInterface |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var NavigatorInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
private $navigator; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var VisitorInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
private $visitor; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var int |
|
39
|
|
|
*/ |
|
40
|
|
|
private $direction; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
private $format; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var bool |
|
49
|
|
|
*/ |
|
50
|
|
|
private $ignoreNull = false; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var ExclusionStrategyInterface |
|
54
|
|
|
*/ |
|
55
|
|
|
private $exclusionStrategy; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var NamingStrategyInterface |
|
59
|
|
|
*/ |
|
60
|
|
|
private $namingStrategy; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var mixed[] |
|
64
|
|
|
*/ |
|
65
|
|
|
private $dataStack; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var MetadataInterface[] |
|
69
|
|
|
*/ |
|
70
|
|
|
private $metadataStack; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param ExclusionStrategyInterface|null $exclusionStrategy |
|
74
|
|
|
* @param NamingStrategyInterface|null $namingStrategy |
|
75
|
|
|
*/ |
|
76
|
792 |
|
public function __construct( |
|
77
|
|
|
ExclusionStrategyInterface $exclusionStrategy = null, |
|
78
|
|
|
NamingStrategyInterface $namingStrategy = null |
|
79
|
|
|
) { |
|
80
|
792 |
|
$this->exclusionStrategy = $exclusionStrategy ?: new ExclusionStrategy(); |
|
81
|
792 |
|
$this->namingStrategy = $namingStrategy ?: new IdenticalNamingStrategy(); |
|
82
|
792 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* {@inheritdoc} |
|
86
|
|
|
*/ |
|
87
|
984 |
|
public function initialize(NavigatorInterface $navigator, VisitorInterface $visitor, $direction, $format) |
|
88
|
|
|
{ |
|
89
|
656 |
|
$this |
|
90
|
984 |
|
->setNavigator($navigator) |
|
91
|
984 |
|
->setVisitor($visitor) |
|
92
|
984 |
|
->setDirection($direction) |
|
93
|
984 |
|
->setFormat($format) |
|
94
|
984 |
|
->setDataStack([]) |
|
95
|
984 |
|
->setMetadataStack([]); |
|
96
|
984 |
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* {@inheritdoc} |
|
100
|
|
|
*/ |
|
101
|
984 |
|
public function getNavigator() |
|
102
|
|
|
{ |
|
103
|
984 |
|
return $this->navigator; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* {@inheritdoc} |
|
108
|
|
|
*/ |
|
109
|
984 |
|
public function setNavigator(NavigatorInterface $navigator) |
|
110
|
|
|
{ |
|
111
|
984 |
|
$this->navigator = $navigator; |
|
112
|
|
|
|
|
113
|
984 |
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* {@inheritdoc} |
|
118
|
|
|
*/ |
|
119
|
984 |
|
public function getVisitor() |
|
120
|
|
|
{ |
|
121
|
984 |
|
return $this->visitor; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* {@inheritdoc} |
|
126
|
|
|
*/ |
|
127
|
984 |
|
public function setVisitor(VisitorInterface $visitor) |
|
128
|
|
|
{ |
|
129
|
984 |
|
$this->visitor = $visitor; |
|
130
|
|
|
|
|
131
|
984 |
|
return $this; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* {@inheritdoc} |
|
136
|
|
|
*/ |
|
137
|
96 |
|
public function getDirection() |
|
138
|
|
|
{ |
|
139
|
96 |
|
return $this->direction; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* {@inheritdoc} |
|
144
|
|
|
*/ |
|
145
|
984 |
|
public function setDirection($direction) |
|
146
|
|
|
{ |
|
147
|
984 |
|
$this->direction = $direction; |
|
148
|
|
|
|
|
149
|
984 |
|
return $this; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* {@inheritdoc} |
|
154
|
|
|
*/ |
|
155
|
|
|
public function getFormat() |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->format; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* {@inheritdoc} |
|
162
|
|
|
*/ |
|
163
|
984 |
|
public function setFormat($format) |
|
164
|
|
|
{ |
|
165
|
984 |
|
$this->format = $format; |
|
166
|
|
|
|
|
167
|
984 |
|
return $this; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* {@inheritdoc} |
|
172
|
|
|
*/ |
|
173
|
195 |
|
public function isNullIgnored() |
|
174
|
|
|
{ |
|
175
|
195 |
|
return $this->ignoreNull; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* {@inheritdoc} |
|
180
|
|
|
*/ |
|
181
|
|
|
public function setIgnoreNull($ignoreNull) |
|
182
|
|
|
{ |
|
183
|
|
|
$this->ignoreNull = $ignoreNull; |
|
184
|
|
|
|
|
185
|
|
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* {@inheritdoc} |
|
190
|
|
|
*/ |
|
191
|
798 |
|
public function getExclusionStrategy() |
|
192
|
|
|
{ |
|
193
|
798 |
|
return $this->exclusionStrategy; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* {@inheritdoc} |
|
198
|
|
|
*/ |
|
199
|
|
|
public function setExclusionStrategy(ExclusionStrategyInterface $exclusionStrategy) |
|
200
|
|
|
{ |
|
201
|
|
|
$this->exclusionStrategy = $exclusionStrategy; |
|
202
|
|
|
|
|
203
|
|
|
return $this; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* {@inheritdoc} |
|
208
|
|
|
*/ |
|
209
|
768 |
|
public function getNamingStrategy() |
|
210
|
|
|
{ |
|
211
|
768 |
|
return $this->namingStrategy; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* {@inheritdoc} |
|
216
|
|
|
*/ |
|
217
|
|
|
public function setNamingStrategy(NamingStrategyInterface $namingStrategy) |
|
218
|
|
|
{ |
|
219
|
|
|
$this->namingStrategy = $namingStrategy; |
|
220
|
|
|
|
|
221
|
|
|
return $this; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* {@inheritdoc} |
|
226
|
|
|
*/ |
|
227
|
24 |
|
public function getDataStack() |
|
228
|
|
|
{ |
|
229
|
24 |
|
return $this->dataStack; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* {@inheritdoc} |
|
234
|
|
|
*/ |
|
235
|
984 |
|
public function setDataStack(array $dataStack) |
|
236
|
|
|
{ |
|
237
|
984 |
|
$this->dataStack = $dataStack; |
|
238
|
|
|
|
|
239
|
984 |
|
return $this; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* {@inheritdoc} |
|
244
|
|
|
*/ |
|
245
|
24 |
|
public function getMetadataStack() |
|
246
|
|
|
{ |
|
247
|
24 |
|
return $this->metadataStack; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* {@inheritdoc} |
|
252
|
|
|
*/ |
|
253
|
984 |
|
public function setMetadataStack(array $metadataStack) |
|
254
|
|
|
{ |
|
255
|
984 |
|
$this->metadataStack = $metadataStack; |
|
256
|
|
|
|
|
257
|
984 |
|
return $this; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* {@inheritdoc} |
|
262
|
|
|
*/ |
|
263
|
798 |
|
public function enterScope($data, MetadataInterface $metadata) |
|
264
|
|
|
{ |
|
265
|
798 |
|
$this->dataStack[] = $data; |
|
266
|
798 |
|
$this->metadataStack[] = $metadata; |
|
267
|
798 |
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* {@inheritdoc} |
|
271
|
|
|
*/ |
|
272
|
798 |
|
public function leaveScope() |
|
273
|
|
|
{ |
|
274
|
798 |
|
array_pop($this->dataStack); |
|
275
|
798 |
|
array_pop($this->metadataStack); |
|
276
|
798 |
|
} |
|
277
|
|
|
} |
|
278
|
|
|
|