From a9dfcd88194c4495bb823bcd4accc65f93ff5b11 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 4 Jan 2017 22:58:24 +0100 Subject: [PATCH] [Cache] Remove silenced warning tiggered by PhpArrayAdapter --- .../Cache/Adapter/PhpArrayAdapter.php | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php index 35fcad9a3af6a..37b885fa32d36 100644 --- a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php +++ b/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(); } /**