From 5a99ed3fa00f0e25461535ffe7afd7ea5b06bd5c Mon Sep 17 00:00:00 2001 From: Arinzechukwu Date: Tue, 27 Sep 2022 14:37:49 +0100 Subject: [PATCH] Added cache for base Spec object properties --- src/SpecBaseObject.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/SpecBaseObject.php b/src/SpecBaseObject.php index 1de429bd..c533ba32 100644 --- a/src/SpecBaseObject.php +++ b/src/SpecBaseObject.php @@ -35,6 +35,8 @@ abstract class SpecBaseObject implements SpecObjectInterface, DocumentContextInt private $_baseDocument; private $_jsonPointer; + private $_context; + /** * @return array array of attributes available in this object. @@ -397,6 +399,13 @@ public function resolveReferences(ReferenceContext $context = null) if ($this->_recursingReferences) { return; } + + $key = isset($this->_jsonPointer) ? $this->_jsonPointer->getPointer() : null; + if ($key && $this->_context && $this->_context->getCache()->has($key,'#properties')) { + $this->_properties = $this->_context->getCache()->get($key,'#properties'); + return; + } + $this->_recursingReferences = true; foreach ($this->_properties as $property => $value) { @@ -423,6 +432,10 @@ public function resolveReferences(ReferenceContext $context = null) } } + if($key && $this->_context ){ + $this->_context->getCache()->set($key,'#properties', $this->_properties); + } + $this->_recursingReferences = false; } @@ -431,6 +444,7 @@ public function resolveReferences(ReferenceContext $context = null) */ public function setReferenceContext(ReferenceContext $context) { + $this->_context = $context; // avoid recursion to get stuck in a loop if ($this->_recursingReferenceContext) { return;