@@ -40,8 +40,6 @@ class Schema extends JsonSchema implements MetaHolder
4040 const VERSION_DRAFT_06 = 6 ;
4141 const VERSION_DRAFT_07 = 7 ;
4242
43- const SCHEMA_DRAFT_04_URL = 'http://json-schema.org/draft-04/schema ' ;
44-
4543 const REF = '$ref ' ;
4644 const ID = '$id ' ;
4745 const ID_D4 = 'id ' ;
@@ -108,47 +106,6 @@ public function addPropertyMapping($dataName, $propertyName, $mapping = self::DE
108106 return $ this ;
109107 }
110108
111- private function preProcessReferences ($ data , Context $ options , $ nestingLevel = 0 )
112- {
113- if ($ nestingLevel > 200 ) {
114- throw new Exception ('Too deep nesting level ' , Exception::DEEP_NESTING );
115- }
116- if (is_array ($ data )) {
117- foreach ($ data as $ key => $ item ) {
118- $ this ->preProcessReferences ($ item , $ options , $ nestingLevel + 1 );
119- }
120- } elseif ($ data instanceof \stdClass) {
121- /** @var JsonSchema $data */
122- if (
123- isset ($ data ->{Schema::ID_D4 })
124- && is_string ($ data ->{Schema::ID_D4 })
125- && (($ options ->version === self ::VERSION_AUTO ) || $ options ->version === self ::VERSION_DRAFT_04 )
126- ) {
127- $ prev = $ options ->refResolver ->setupResolutionScope ($ data ->{Schema::ID_D4 }, $ data );
128- /** @noinspection PhpUnusedLocalVariableInspection */
129- $ _ = new ScopeExit (function () use ($ prev , $ options ) {
130- $ options ->refResolver ->setResolutionScope ($ prev );
131- });
132- }
133-
134- if (isset ($ data ->{self ::ID })
135- && is_string ($ data ->{self ::ID })
136- && (($ options ->version === self ::VERSION_AUTO ) || $ options ->version >= self ::VERSION_DRAFT_06 )
137- ) {
138- $ prev = $ options ->refResolver ->setupResolutionScope ($ data ->{self ::ID }, $ data );
139- /** @noinspection PhpUnusedLocalVariableInspection */
140- $ _ = new ScopeExit (function () use ($ prev , $ options ) {
141- $ options ->refResolver ->setResolutionScope ($ prev );
142- });
143- }
144-
145-
146- foreach ((array )$ data as $ key => $ value ) {
147- $ this ->preProcessReferences ($ value , $ options , $ nestingLevel + 1 );
148- }
149- }
150- }
151-
152109 public static function import ($ data , Context $ options = null )
153110 {
154111 // string $data is expected to be $ref uri
@@ -160,6 +117,14 @@ public static function import($data, Context $options = null)
160117 return parent ::import ($ data , $ options );
161118 }
162119
120+ /**
121+ * @param $data
122+ * @param Context|null $options
123+ * @return array|mixed|null|object|\stdClass
124+ * @throws Exception
125+ * @throws InvalidValue
126+ * @throws \Exception
127+ */
163128 public function in ($ data , Context $ options = null )
164129 {
165130 if ($ options === null ) {
@@ -168,13 +133,18 @@ public function in($data, Context $options = null)
168133
169134 $ options ->import = true ;
170135
171- $ options ->refResolver = new RefResolver ($ data );
136+ if ($ options ->refResolver === null ) {
137+ $ options ->refResolver = new RefResolver ($ data );
138+ } else {
139+ $ options ->refResolver ->setRootData ($ data );
140+ }
141+
172142 if ($ options ->remoteRefProvider ) {
173143 $ options ->refResolver ->setRemoteRefProvider ($ options ->remoteRefProvider );
174144 }
175145
176146 if ($ options ->import ) {
177- $ this ->preProcessReferences ($ data , $ options );
147+ $ options -> refResolver ->preProcessReferences ($ data , $ options );
178148 }
179149
180150 return $ this ->process ($ data , $ options , '# ' );
0 commit comments