@@ -129,6 +129,29 @@ public function retrieve($uri, $baseUri = null)
129
129
$ fetchUri = $ resolver ->generate ($ arParts );
130
130
}
131
131
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
+
132
155
$ uriRetriever = $ this ->getUriRetriever ();
133
156
$ contents = $ this ->uriRetriever ->retrieve ($ fetchUri );
134
157
$ this ->confirmMediaType ($ uriRetriever );
@@ -138,10 +161,7 @@ public function retrieve($uri, $baseUri = null)
138
161
throw new JsonDecodingException ($ error );
139
162
}
140
163
141
- // Use the JSON pointer if specified
142
- $ jsonSchema = $ this ->resolvePointer ($ jsonSchema , $ resolvedUri );
143
- $ jsonSchema ->id = $ resolvedUri ;
144
-
164
+ $ this ->schemaCache [$ fetchUri ] = $ jsonSchema ;
145
165
return $ jsonSchema ;
146
166
}
147
167
0 commit comments