Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/6878-undefined-index-errors-in-memory-adapter-on…
Browse files Browse the repository at this point in the history
…-undefined-namespaces' into develop

Close zendframework/zendframework#6878
Forward port zendframework/zendframework#6878
  • Loading branch information
Ocramius committed Nov 22, 2014
2 parents 7224f51 + 54e0bca commit cb5b7d7
Showing 1 changed file with 22 additions and 32 deletions.
54 changes: 22 additions & 32 deletions Memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,12 @@ public function clearByPrefix($prefix)
public function setTags($key, array $tags)
{
$ns = $this->getOptions()->getNamespace();
if (!$this->data[$ns]) {
if (!isset($this->data[$ns][$key])) {
return false;
}

$data = & $this->data[$ns];
if (isset($data[$key])) {
$data[$key]['tags'] = $tags;
return true;
}

return false;
$this->data[$ns][$key]['tags'] = $tags;
return true;
}

/**
Expand All @@ -249,16 +244,11 @@ public function setTags($key, array $tags)
public function getTags($key)
{
$ns = $this->getOptions()->getNamespace();
if (!$this->data[$ns]) {
return false;
}

$data = & $this->data[$ns];
if (!isset($data[$key])) {
if (!isset($this->data[$ns][$key])) {
return false;
}

return isset($data[$key]['tags']) ? $data[$key]['tags'] : array();
return isset($this->data[$ns][$key]['tags']) ? $this->data[$ns][$key]['tags'] : array();
}

/**
Expand All @@ -274,7 +264,7 @@ public function getTags($key)
public function clearByTags(array $tags, $disjunction = false)
{
$ns = $this->getOptions()->getNamespace();
if (!$this->data[$ns]) {
if (!isset($this->data[$ns])) {
return true;
}

Expand Down Expand Up @@ -654,16 +644,16 @@ protected function internalRemoveItem(& $normalizedKey)
*/
protected function internalIncrementItem(& $normalizedKey, & $value)
{
$ns = $this->getOptions()->getNamespace();
$data = & $this->data[$ns];
if (isset($data[$normalizedKey])) {
$data[$normalizedKey][0]+= $value;
$data[$normalizedKey][1] = microtime(true);
$newValue = $data[$normalizedKey][0];
$ns = $this->getOptions()->getNamespace();
if (isset($this->data[$ns][$normalizedKey])) {
$data = & $this->data[$ns][$normalizedKey];
$data[0]+= $value;
$data[1] = microtime(true);
$newValue = $data[0];
} else {
// initial value
$newValue = $value;
$data[$normalizedKey] = array($newValue, microtime(true));
$newValue = $value;
$this->data[$ns][$normalizedKey] = array($newValue, microtime(true));
}

return $newValue;
Expand All @@ -679,16 +669,16 @@ protected function internalIncrementItem(& $normalizedKey, & $value)
*/
protected function internalDecrementItem(& $normalizedKey, & $value)
{
$ns = $this->getOptions()->getNamespace();
$data = & $this->data[$ns];
if (isset($data[$normalizedKey])) {
$data[$normalizedKey][0]-= $value;
$data[$normalizedKey][1] = microtime(true);
$newValue = $data[$normalizedKey][0];
$ns = $this->getOptions()->getNamespace();
if (isset($this->data[$ns][$normalizedKey])) {
$data = & $this->data[$ns][$normalizedKey];
$data[0]-= $value;
$data[1] = microtime(true);
$newValue = $data[0];
} else {
// initial value
$newValue = -$value;
$data[$normalizedKey] = array($newValue, microtime(true));
$newValue = -$value;
$this->data[$ns][$normalizedKey] = array($newValue, microtime(true));
}

return $newValue;
Expand Down

0 comments on commit cb5b7d7

Please sign in to comment.