@@ -1025,25 +1025,35 @@ public function process($data, Context $options, $path = '#', $result = null)
10251025 if ('# ' === $ path ) {
10261026 $ injectDefinitions = new ScopeExit (function () use ($ result , $ options ) {
10271027 foreach ($ options ->exportedDefinitions as $ ref => $ data ) {
1028- JsonPointer::add ($ result , JsonPointer::splitPath ($ ref ), $ data ,
1029- JsonPointer::SKIP_IF_ISSET + JsonPointer::RECURSIVE_KEY_CREATION );
1028+ if ($ data !== null ) {
1029+ JsonPointer::add ($ result , JsonPointer::splitPath ($ ref ), $ data ,
1030+ /*JsonPointer::SKIP_IF_ISSET + */
1031+ JsonPointer::RECURSIVE_KEY_CREATION );
1032+ }
10301033 }
10311034 });
10321035 }
10331036
1034- if ('# ' !== $ path && $ ref = $ data ->getFromRef ()) {
1035- if ($ ref [0 ] === '# ' ) {
1036- if (isset ($ options ->exportedDefinitions [$ ref ])) {
1037- $ result ->{self ::PROP_REF } = $ ref ;
1038- return $ result ;
1039- } elseif (!array_key_exists ($ ref , $ options ->exportedDefinitions )) {
1040- $ exported = null ;
1041- $ options ->exportedDefinitions [$ ref ] = &$ exported ;
1042- $ exported = $ this ->process ($ data , $ options , $ ref );
1043- $ result ->{self ::PROP_REF } = $ ref ;
1044- return $ result ;
1037+ if ('# ' !== $ path && $ refs = $ data ->getFromRefs ()) {
1038+ $ ref = $ refs [0 ];
1039+ if (!array_key_exists ($ ref , $ options ->exportedDefinitions )) {
1040+ $ exported = null ;
1041+ $ options ->exportedDefinitions [$ ref ] = &$ exported ;
1042+ $ exported = $ this ->process ($ data , $ options /*, $ref*/ );
1043+ unset($ exported );
1044+ }
1045+
1046+ for ($ i = 1 ; $ i < count ($ refs ); $ i ++) {
1047+ $ ref = $ refs [$ i ];
1048+ if (!array_key_exists ($ ref , $ options ->exportedDefinitions )) {
1049+ $ exported = new \stdClass ();
1050+ $ exported ->{self ::PROP_REF } = $ refs [$ i -1 ];
1051+ $ options ->exportedDefinitions [$ ref ] = $ exported ;
10451052 }
10461053 }
1054+
1055+ $ result ->{self ::PROP_REF } = $ refs [count ($ refs ) - 1 ];
1056+ return $ result ;
10471057 }
10481058
10491059 if ($ options ->circularReferences ->contains ($ data )) {
0 commit comments