Commit df52510f by Qiang Xue

fixed potential problem about using unset variables.

CS fix.
parent 505cb7d6
...@@ -232,14 +232,14 @@ abstract class Cache extends Component implements \ArrayAccess ...@@ -232,14 +232,14 @@ abstract class Cache extends Component implements \ArrayAccess
$data = []; $data = [];
foreach ($items as $key => $value) { foreach ($items as $key => $value) {
$itemKey = $this->buildKey($key);
if ($this->serializer === null) { if ($this->serializer === null) {
$itemValue = serialize([$value, $dependency]); $value = serialize([$value, $dependency]);
} elseif ($this->serializer !== false) { } elseif ($this->serializer !== false) {
$itemValue = call_user_func($this->serializer[0], [$value, $dependency]); $value = call_user_func($this->serializer[0], [$value, $dependency]);
} }
$data[$itemKey] = $itemValue; $key = $this->buildKey($key);
$data[$key] = $value;
} }
return $this->setValues($data, $expire); return $this->setValues($data, $expire);
} }
...@@ -263,14 +263,14 @@ abstract class Cache extends Component implements \ArrayAccess ...@@ -263,14 +263,14 @@ abstract class Cache extends Component implements \ArrayAccess
$data = []; $data = [];
foreach ($items as $key => $value) { foreach ($items as $key => $value) {
$itemKey = $this->buildKey($key);
if ($this->serializer === null) { if ($this->serializer === null) {
$itemValue = serialize([$value, $dependency]); $value = serialize([$value, $dependency]);
} elseif ($this->serializer !== false) { } elseif ($this->serializer !== false) {
$itemValue = call_user_func($this->serializer[0], [$value, $dependency]); $value = call_user_func($this->serializer[0], [$value, $dependency]);
} }
$data[$itemKey] = $itemValue; $key = $this->buildKey($key);
$data[$key] = $value;
} }
return $this->addValues($data, $expire); return $this->addValues($data, $expire);
} }
...@@ -389,7 +389,7 @@ abstract class Cache extends Component implements \ArrayAccess ...@@ -389,7 +389,7 @@ abstract class Cache extends Component implements \ArrayAccess
/** /**
* Stores multiple key-value pairs in cache. * Stores multiple key-value pairs in cache.
* The default implementation calls [[setValue()]] multiple times store values one by one. If the underlying cache * The default implementation calls [[setValue()]] multiple times store values one by one. If the underlying cache
* storage supports multiset, this method should be overridden to exploit that feature. * storage supports multi-set, this method should be overridden to exploit that feature.
* @param array $data array where key corresponds to cache key while value is the value stored * @param array $data array where key corresponds to cache key while value is the value stored
* @param integer $expire the number of seconds in which the cached values will expire. 0 means never expire. * @param integer $expire the number of seconds in which the cached values will expire. 0 means never expire.
* @return array array of failed keys * @return array array of failed keys
...@@ -397,8 +397,7 @@ abstract class Cache extends Component implements \ArrayAccess ...@@ -397,8 +397,7 @@ abstract class Cache extends Component implements \ArrayAccess
protected function setValues($data, $expire) protected function setValues($data, $expire)
{ {
$failedKeys = []; $failedKeys = [];
foreach ($data as $key => $value) foreach ($data as $key => $value) {
{
if ($this->setValue($key, $value, $expire) === false) { if ($this->setValue($key, $value, $expire) === false) {
$failedKeys[] = $key; $failedKeys[] = $key;
} }
...@@ -409,7 +408,7 @@ abstract class Cache extends Component implements \ArrayAccess ...@@ -409,7 +408,7 @@ abstract class Cache extends Component implements \ArrayAccess
/** /**
* Adds multiple key-value pairs to cache. * Adds multiple key-value pairs to cache.
* The default implementation calls [[addValue()]] multiple times add values one by one. If the underlying cache * The default implementation calls [[addValue()]] multiple times add values one by one. If the underlying cache
* storage supports multiadd, this method should be overridden to exploit that feature. * storage supports multi-add, this method should be overridden to exploit that feature.
* @param array $data array where key corresponds to cache key while value is the value stored * @param array $data array where key corresponds to cache key while value is the value stored
* @param integer $expire the number of seconds in which the cached values will expire. 0 means never expire. * @param integer $expire the number of seconds in which the cached values will expire. 0 means never expire.
* @return array array of failed keys * @return array array of failed keys
...@@ -417,8 +416,7 @@ abstract class Cache extends Component implements \ArrayAccess ...@@ -417,8 +416,7 @@ abstract class Cache extends Component implements \ArrayAccess
protected function addValues($data, $expire) protected function addValues($data, $expire)
{ {
$failedKeys = []; $failedKeys = [];
foreach ($data as $key => $value) foreach ($data as $key => $value) {
{
if ($this->addValue($key, $value, $expire) === false) { if ($this->addValue($key, $value, $expire) === false) {
$failedKeys[] = $key; $failedKeys[] = $key;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment