Skip to content

Commit

Permalink
bug #21167 [Cache] Remove silenced warning tiggered by PhpArrayAdapte…
Browse files Browse the repository at this point in the history
…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 bfda99f
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -265,10 +260,6 @@ public function deleteItem($key)
*/
public function deleteItems(array $keys)
{
if (null === $this->values) {
$this->initialize();
}

$deleted = true;
$fallbackKeys = array();

Expand All @@ -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;
Expand Down Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit bfda99f

Please sign in to comment.