@@ -24,7 +24,13 @@ abstract class SpecBaseObject implements SpecObjectInterface, DocumentContextInt
24
24
{
25
25
private $ _properties = [];
26
26
private $ _errors = [];
27
- private $ _recursing = false ;
27
+
28
+ private $ _recursingSerializableData = false ;
29
+ private $ _recursingValidate = false ;
30
+ private $ _recursingErrors = false ;
31
+ private $ _recursingReferences = false ;
32
+ private $ _recursingReferenceContext = false ;
33
+ private $ _recursingDocumentContext = false ;
28
34
29
35
private $ _baseDocument ;
30
36
private $ _jsonPointer ;
@@ -168,11 +174,11 @@ protected function instantiate($type, $data)
168
174
*/
169
175
public function getSerializableData ()
170
176
{
171
- if ($ this ->_recursing ) {
177
+ if ($ this ->_recursingSerializableData ) {
172
178
// return a reference
173
179
return (object ) ['$ref ' => JsonReference::createFromUri ('' , $ this ->getDocumentPosition ())->getReference ()];
174
180
}
175
- $ this ->_recursing = true ;
181
+ $ this ->_recursingSerializableData = true ;
176
182
177
183
$ data = $ this ->_properties ;
178
184
foreach ($ data as $ k => $ v ) {
@@ -195,7 +201,7 @@ public function getSerializableData()
195
201
}
196
202
}
197
203
198
- $ this ->_recursing = false ;
204
+ $ this ->_recursingSerializableData = false ;
199
205
200
206
return (object ) $ data ;
201
207
}
@@ -208,10 +214,10 @@ public function getSerializableData()
208
214
public function validate (): bool
209
215
{
210
216
// avoid recursion to get stuck in a loop
211
- if ($ this ->_recursing ) {
217
+ if ($ this ->_recursingValidate ) {
212
218
return true ;
213
219
}
214
- $ this ->_recursing = true ;
220
+ $ this ->_recursingValidate = true ;
215
221
$ valid = true ;
216
222
foreach ($ this ->_properties as $ v ) {
217
223
if ($ v instanceof SpecObjectInterface) {
@@ -228,7 +234,7 @@ public function validate(): bool
228
234
}
229
235
}
230
236
}
231
- $ this ->_recursing = false ;
237
+ $ this ->_recursingValidate = false ;
232
238
233
239
$ this ->performValidation ();
234
240
@@ -246,10 +252,10 @@ public function validate(): bool
246
252
public function getErrors (): array
247
253
{
248
254
// avoid recursion to get stuck in a loop
249
- if ($ this ->_recursing ) {
255
+ if ($ this ->_recursingErrors ) {
250
256
return [];
251
257
}
252
- $ this ->_recursing = true ;
258
+ $ this ->_recursingErrors = true ;
253
259
254
260
if (($ pos = $ this ->getDocumentPosition ()) !== null ) {
255
261
$ errors = [
@@ -272,7 +278,7 @@ public function getErrors(): array
272
278
}
273
279
}
274
280
275
- $ this ->_recursing = false ;
281
+ $ this ->_recursingErrors = false ;
276
282
277
283
return array_merge (...$ errors );
278
284
}
@@ -360,10 +366,10 @@ public function __unset($name)
360
366
public function resolveReferences (ReferenceContext $ context = null )
361
367
{
362
368
// avoid recursion to get stuck in a loop
363
- if ($ this ->_recursing ) {
369
+ if ($ this ->_recursingReferences ) {
364
370
return ;
365
371
}
366
- $ this ->_recursing = true ;
372
+ $ this ->_recursingReferences = true ;
367
373
368
374
foreach ($ this ->_properties as $ property => $ value ) {
369
375
if ($ value instanceof Reference) {
@@ -389,14 +395,20 @@ public function resolveReferences(ReferenceContext $context = null)
389
395
}
390
396
}
391
397
392
- $ this ->_recursing = false ;
398
+ $ this ->_recursingReferences = false ;
393
399
}
394
400
395
401
/**
396
402
* Set context for all Reference Objects in this object.
397
403
*/
398
404
public function setReferenceContext (ReferenceContext $ context )
399
405
{
406
+ // avoid recursion to get stuck in a loop
407
+ if ($ this ->_recursingReferenceContext ) {
408
+ return ;
409
+ }
410
+ $ this ->_recursingReferenceContext = true ;
411
+
400
412
foreach ($ this ->_properties as $ property => $ value ) {
401
413
if ($ value instanceof Reference) {
402
414
$ value ->setContext ($ context );
@@ -412,6 +424,8 @@ public function setReferenceContext(ReferenceContext $context)
412
424
}
413
425
}
414
426
}
427
+
428
+ $ this ->_recursingReferenceContext = false ;
415
429
}
416
430
417
431
/**
@@ -428,10 +442,10 @@ public function setDocumentContext(SpecObjectInterface $baseDocument, JsonPointe
428
442
$ this ->_jsonPointer = $ jsonPointer ;
429
443
430
444
// avoid recursion to get stuck in a loop
431
- if ($ this ->_recursing ) {
445
+ if ($ this ->_recursingDocumentContext ) {
432
446
return ;
433
447
}
434
- $ this ->_recursing = true ;
448
+ $ this ->_recursingDocumentContext = true ;
435
449
436
450
foreach ($ this ->_properties as $ property => $ value ) {
437
451
if ($ value instanceof DocumentContextInterface) {
@@ -445,7 +459,7 @@ public function setDocumentContext(SpecObjectInterface $baseDocument, JsonPointe
445
459
}
446
460
}
447
461
448
- $ this ->_recursing = false ;
462
+ $ this ->_recursingDocumentContext = false ;
449
463
}
450
464
451
465
/**
0 commit comments