Skip to content
Permalink
Browse files

bug #21167 [Cache] Remove silenced warning tiggered by PhpArrayAdapte…

…r (nicolas-grekas)

This PR was merged into the 3.2 branch.

Discussion
----------

[Cache] Remove silenced warning tiggered by PhpArrayAdapter

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Because many reported this silenced warning, which happens all the time unless `cache:warmup` has been run.

Commits
-------

a9dfcd8 [Cache] Remove silenced warning tiggered by PhpArrayAdapter
  • Loading branch information...
nicolas-grekas committed Jan 5, 2017
2 parents c74220f + a9dfcd8 commit bfda99f2eb88046ab822bcbe4284a7b1ba40499d
Showing with 16 additions and 22 deletions.
  1. +16 −22 src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
@@ -163,14 +163,12 @@ public function warmUp(array $values)
*/
public function getItem($key)
{
if (null === $this->values) {
$this->initialize();
}
if (!is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
}
if (null === $this->values) {
$this->initialize();
}
if (!isset($this->values[$key])) {
return $this->fallbackPool->getItem($key);
}
@@ -203,15 +201,14 @@ public function getItem($key)
*/
public function getItems(array $keys = array())
{
if (null === $this->values) {
$this->initialize();
}
foreach ($keys as $key) {
if (!is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
}
}
if (null === $this->values) {
$this->initialize();
}
return $this->generateItems($keys);
}
@@ -221,13 +218,12 @@ public function getItems(array $keys = array())
*/
public function hasItem($key)
{
if (null === $this->values) {
$this->initialize();
}
if (!is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
}
if (null === $this->values) {
$this->initialize();
}
return isset($this->values[$key]) || $this->fallbackPool->hasItem($key);
}
@@ -249,13 +245,12 @@ public function clear()
*/
public function deleteItem($key)
{
if (null === $this->values) {
$this->initialize();
}
if (!is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
}
if (null === $this->values) {
$this->initialize();
}
return !isset($this->values[$key]) && $this->fallbackPool->deleteItem($key);
}
@@ -265,10 +260,6 @@ public function deleteItem($key)
*/
public function deleteItems(array $keys)
{
if (null === $this->values) {
$this->initialize();
}
$deleted = true;
$fallbackKeys = array();
@@ -283,6 +274,9 @@ public function deleteItems(array $keys)
$fallbackKeys[] = $key;
}
}
if (null === $this->values) {
$this->initialize();
}
if ($fallbackKeys) {
$deleted = $this->fallbackPool->deleteItems($fallbackKeys) && $deleted;
@@ -328,7 +322,7 @@ public function commit()
*/
private function initialize()
{
$this->values = @(include $this->file) ?: array();
$this->values = file_exists($this->file) ? (include $this->file ?: array()) : array();
}
/**

0 comments on commit bfda99f

Please sign in to comment.
You can’t perform that action at this time.