Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/spec/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
*/
class Reference implements SpecObjectInterface, DocumentContextInterface
{
static $file_cache = [];

private $_to;
private $_ref;
private $_jsonReference;
Expand Down Expand Up @@ -206,7 +208,7 @@ public function resolve(ReferenceContext $context = null)
// resolve in external document
$file = $context->resolveRelativeUri($jsonReference->getDocumentUri());
// TODO could be a good idea to cache loaded files in current context to avoid loading the same files over and over again
$referencedDocument = $this->fetchReferencedFile($file);
$referencedDocument = $this->getReferencedFile($file);
$referencedData = $jsonReference->getJsonPointer()->evaluate($referencedDocument);

if ($referencedData === null) {
Expand Down Expand Up @@ -258,6 +260,18 @@ public function resolve(ReferenceContext $context = null)
}
}

/**
* @throws UnresolvableReferenceException
*/
private function getReferencedFile($uri)
{
if(!isset(self::$file_cache[$uri])) {
self::$file_cache[$uri] = $this->fetchReferencedFile($uri);
}

return self::$file_cache[$uri];
}

/**
* @throws UnresolvableReferenceException
*/
Expand Down