@@ -75,18 +75,28 @@ public function __construct(array $data)
75
75
}
76
76
switch (\count ($ type )) {
77
77
case 1 :
78
- // array
79
- $ this ->_properties [$ property ] = [];
80
- foreach ($ data [$ property ] as $ item ) {
81
- if ($ type [0 ] === Type::STRING ) {
82
- if (!is_string ($ item )) {
83
- $ this ->_errors [] = "property ' $ property' must be array of strings, but array has " . gettype ($ item ) . " element. " ;
78
+ if (isset ($ data [$ property ]['$ref ' ])) {
79
+ $ this ->_properties [$ property ] = new Reference ($ data [$ property ], null );
80
+ } else {
81
+ // array
82
+ $ this ->_properties [$ property ] = [];
83
+ foreach ($ data [$ property ] as $ item ) {
84
+ if ($ type [0 ] === Type::STRING ) {
85
+ if (!is_string ($ item )) {
86
+ $ this ->_errors [] = "property ' $ property' must be array of strings, but array has " . gettype ($ item ) . " element. " ;
87
+ }
88
+ $ this ->_properties [$ property ][] = $ item ;
89
+ } elseif (Type::isScalar ($ type [0 ])) {
90
+ $ this ->_properties [$ property ][] = $ item ;
91
+ } elseif ($ type [0 ] === Type::ANY ) {
92
+ if (is_array ($ item ) && isset ($ item ['$ref ' ])) {
93
+ $ this ->_properties [$ property ][] = new Reference ($ item , null );
94
+ } else {
95
+ $ this ->_properties [$ property ][] = $ item ;
96
+ }
97
+ } else {
98
+ $ this ->_properties [$ property ][] = $ this ->instantiate ($ type [0 ], $ item );
84
99
}
85
- $ this ->_properties [$ property ][] = $ item ;
86
- } elseif ($ type [0 ] === Type::ANY || Type::isScalar ($ type [0 ])) {
87
- $ this ->_properties [$ property ][] = $ item ;
88
- } else {
89
- $ this ->_properties [$ property ][] = $ this ->instantiate ($ type [0 ], $ item );
90
100
}
91
101
}
92
102
break ;
@@ -110,8 +120,14 @@ public function __construct(array $data)
110
120
}
111
121
break ;
112
122
}
113
- } elseif ($ type === Type:: ANY || Type::isScalar ($ type )) {
123
+ } elseif (Type::isScalar ($ type )) {
114
124
$ this ->_properties [$ property ] = $ data [$ property ];
125
+ } elseif ($ type === Type::ANY ) {
126
+ if (is_array ($ data [$ property ]) && isset ($ data [$ property ]['$ref ' ])) {
127
+ $ this ->_properties [$ property ] = new Reference ($ data [$ property ], null );
128
+ } else {
129
+ $ this ->_properties [$ property ] = $ data [$ property ];
130
+ }
115
131
} else {
116
132
$ this ->_properties [$ property ] = $ this ->instantiate ($ type , $ data [$ property ]);
117
133
}
@@ -353,7 +369,7 @@ public function resolveReferences(ReferenceContext $context = null)
353
369
if ($ value instanceof Reference) {
354
370
$ referencedObject = $ value ->resolve ($ context );
355
371
$ this ->_properties [$ property ] = $ referencedObject ;
356
- if (!$ referencedObject instanceof Reference && $ referencedObject !== null ) {
372
+ if (!$ referencedObject instanceof Reference && $ referencedObject instanceof SpecObjectInterface ) {
357
373
$ referencedObject ->resolveReferences ();
358
374
}
359
375
} elseif ($ value instanceof SpecObjectInterface) {
@@ -363,7 +379,7 @@ public function resolveReferences(ReferenceContext $context = null)
363
379
if ($ item instanceof Reference) {
364
380
$ referencedObject = $ item ->resolve ($ context );
365
381
$ this ->_properties [$ property ][$ k ] = $ referencedObject ;
366
- if (!$ referencedObject instanceof Reference && $ referencedObject !== null ) {
382
+ if (!$ referencedObject instanceof Reference && $ referencedObject instanceof SpecObjectInterface ) {
367
383
$ referencedObject ->resolveReferences ();
368
384
}
369
385
} elseif ($ item instanceof SpecObjectInterface) {
0 commit comments