Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cache for base Spec object properties #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions src/SpecBaseObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down