@@ -96,6 +96,7 @@ class Schema extends MagicMap
9696 public $ oneOf ;
9797
9898 public $ objectItemClass ;
99+ private $ useObjectAsArray = false ;
99100
100101 public function import ($ data , DataPreProcessor $ preProcessor = null )
101102 {
@@ -112,6 +113,10 @@ private function process($data, $import = true, DataPreProcessor $preProcessor =
112113 if (!$ import && $ data instanceof ObjectItem) {
113114 $ data = $ data ->jsonSerialize ();
114115 }
116+ if (!$ import && is_array ($ data ) && $ this ->useObjectAsArray ) {
117+ $ data = (object )$ data ;
118+ }
119+
115120 if (null !== $ preProcessor ) {
116121 $ data = $ preProcessor ->process ($ data , $ this , $ import );
117122 }
@@ -254,8 +259,6 @@ private function process($data, $import = true, DataPreProcessor $preProcessor =
254259 }
255260 }
256261 }
257-
258-
259262 }
260263
261264 if ($ data instanceof \stdClass) {
@@ -267,16 +270,21 @@ private function process($data, $import = true, DataPreProcessor $preProcessor =
267270 }
268271 }
269272
270- if ($ import && !$ result instanceof ObjectItem) {
271- $ result = $ this ->makeObjectItem ();
272273
273- if ($ result instanceof ClassStructure) {
274- if ($ result ->__validateOnSet ) {
275- $ result ->__validateOnSet = false ;
276- /** @noinspection PhpUnusedLocalVariableInspection */
277- $ validateOnSetHandler = new ScopeExit (function () use ($ result ) {
278- $ result ->__validateOnSet = true ;
279- });
274+ if ($ import ) {
275+ if ($ this ->useObjectAsArray ) {
276+ $ result = array ();
277+ } elseif (!$ result instanceof ObjectItem) {
278+ $ result = $ this ->makeObjectItem ();
279+
280+ if ($ result instanceof ClassStructure) {
281+ if ($ result ->__validateOnSet ) {
282+ $ result ->__validateOnSet = false ;
283+ /** @noinspection PhpUnusedLocalVariableInspection */
284+ $ validateOnSetHandler = new ScopeExit (function () use ($ result ) {
285+ $ result ->__validateOnSet = true ;
286+ });
287+ }
280288 }
281289 }
282290 }
@@ -344,7 +352,7 @@ private function process($data, $import = true, DataPreProcessor $preProcessor =
344352 }
345353
346354 $ value = $ this ->additionalProperties ->process ($ value , $ import , $ preProcessor , $ path . '->additionalProperties ' );
347- if ($ import ) {
355+ if ($ import && ! $ this -> useObjectAsArray ) {
348356 $ result ->addAdditionalPropertyName ($ key );
349357 }
350358 }
@@ -357,7 +365,11 @@ private function process($data, $import = true, DataPreProcessor $preProcessor =
357365 $ result ->$ key = $ value ;
358366 }
359367 } else {
360- $ result ->$ key = $ value ;
368+ if ($ this ->useObjectAsArray && $ import ) {
369+ $ result [$ key ] = $ value ;
370+ } else {
371+ $ result ->$ key = $ value ;
372+ }
361373 }
362374
363375 }
@@ -418,6 +430,16 @@ private function process($data, $import = true, DataPreProcessor $preProcessor =
418430 return $ result ;
419431 }
420432
433+ /**
434+ * @param boolean $useObjectAsArray
435+ * @return Schema
436+ */
437+ public function setUseObjectAsArray ($ useObjectAsArray )
438+ {
439+ $ this ->useObjectAsArray = $ useObjectAsArray ;
440+ return $ this ;
441+ }
442+
421443 /**
422444 * @param bool|Schema $additionalProperties
423445 * @return Schema
0 commit comments