Skip to content

Commit ae66308

Browse files
author
Christian Weiske
committed
cache fetched schema object; needed for recursively nested schemas
1 parent a01a52e commit ae66308

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/JsonSchema/Uri/UriRetriever.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,29 @@ public function retrieve($uri, $baseUri = null)
129129
$fetchUri = $resolver->generate($arParts);
130130
}
131131

132+
$jsonSchema = $this->loadSchema($fetchUri);
133+
134+
// Use the JSON pointer if specified
135+
$jsonSchema = $this->resolvePointer($jsonSchema, $resolvedUri);
136+
$jsonSchema->id = $resolvedUri;
137+
138+
return $jsonSchema;
139+
}
140+
141+
/**
142+
* Fetch a schema from the given URI, json-decode it and return it.
143+
* Caches schema objects.
144+
*
145+
* @param string $fetchUri Absolute URI
146+
*
147+
* @return object JSON schema object
148+
*/
149+
protected function loadSchema($fetchUri)
150+
{
151+
if (isset($this->schemaCache[$fetchUri])) {
152+
return $this->schemaCache[$fetchUri];
153+
}
154+
132155
$uriRetriever = $this->getUriRetriever();
133156
$contents = $this->uriRetriever->retrieve($fetchUri);
134157
$this->confirmMediaType($uriRetriever);
@@ -138,10 +161,7 @@ public function retrieve($uri, $baseUri = null)
138161
throw new JsonDecodingException($error);
139162
}
140163

141-
// Use the JSON pointer if specified
142-
$jsonSchema = $this->resolvePointer($jsonSchema, $resolvedUri);
143-
$jsonSchema->id = $resolvedUri;
144-
164+
$this->schemaCache[$fetchUri] = $jsonSchema;
145165
return $jsonSchema;
146166
}
147167

0 commit comments

Comments
 (0)