@@ -134,6 +134,29 @@ public function retrieve($uri, $baseUri = null)
134
134
$ fetchUri = $ resolver ->generate ($ arParts );
135
135
}
136
136
137
+ $ jsonSchema = $ this ->loadSchema ($ fetchUri );
138
+
139
+ // Use the JSON pointer if specified
140
+ $ jsonSchema = $ this ->resolvePointer ($ jsonSchema , $ resolvedUri );
141
+ $ jsonSchema ->id = $ resolvedUri ;
142
+
143
+ return $ jsonSchema ;
144
+ }
145
+
146
+ /**
147
+ * Fetch a schema from the given URI, json-decode it and return it.
148
+ * Caches schema objects.
149
+ *
150
+ * @param string $fetchUri Absolute URI
151
+ *
152
+ * @return object JSON schema object
153
+ */
154
+ protected function loadSchema ($ fetchUri )
155
+ {
156
+ if (isset ($ this ->schemaCache [$ fetchUri ])) {
157
+ return $ this ->schemaCache [$ fetchUri ];
158
+ }
159
+
137
160
$ uriRetriever = $ this ->getUriRetriever ();
138
161
$ contents = $ this ->uriRetriever ->retrieve ($ fetchUri );
139
162
$ this ->confirmMediaType ($ uriRetriever , $ fetchUri );
@@ -143,10 +166,7 @@ public function retrieve($uri, $baseUri = null)
143
166
throw new JsonDecodingException ($ error );
144
167
}
145
168
146
- // Use the JSON pointer if specified
147
- $ jsonSchema = $ this ->resolvePointer ($ jsonSchema , $ resolvedUri );
148
- $ jsonSchema ->id = $ resolvedUri ;
149
-
169
+ $ this ->schemaCache [$ fetchUri ] = $ jsonSchema ;
150
170
return $ jsonSchema ;
151
171
}
152
172
0 commit comments