8000 bug #21167 [Cache] Remove silenced warning tiggered by PhpArrayAdapte… · symfony/symfony@bfda99f · GitHub
[go: up one dir, main page]

Skip to content

Commit bfda99f

Browse files
bug #21167 [Cache] Remove silenced warning tiggered by PhpArrayAdapter (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
2 parents c74220f + a9dfcd8 commit bfda99f

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,12 @@ public function warmUp(array $values)
163163
*/
164164
public function getItem($key)
165165
{
166-
if (null === $this->values) {
167-
$this->initialize();
168-
}
169-
170166
if (!is_string($key)) {
171167
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
172168
}
173-
169+
if (null === $this->values) {
170+
$this->initialize();
171+
}
174172
if (!isset($this->values[$key])) {
175173
return $this->fallbackPool->getItem($key);
176174
}
@@ -203,15 +201,14 @@ public function getItem($key)
203201
*/
204202
public function getItems(array $keys = array())
205203
{
206-
if (null === $this->values) {
207-
$this->initialize();
208-
}
209-
210204
foreach ($keys as $key) {
211205
if (!is_string($key)) {
212206
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
213207
}
214208
}
209+
if (null === $this->values) {
210+
$this->initialize();
211+
}
215212

216213
return $this->generateItems($keys);
217214
}
@@ -221,13 +218,12 @@ public function getItems(array $keys = array())
221218
*/
222219
public function hasItem($key)
223220
{
224-
if (null === $this->values) {
225-
$this->initialize();
226-
}
227-
228221
if (!is_string($key)) {
229222
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
230223
}
224+
if (null === $this->values) {
225+
$this->initialize();
226+
}
231227

232228
return isset($this->values[$key]) || $this->fallbackPool->hasItem($key);
233229
}
@@ -249,13 +245,12 @@ public function clear()
249245
*/
250246
public function deleteItem($key)
251247
{
252-
if (null === $this->values) {
253-
$this->initialize();
254-
}
255-
256248
if (!is_string($key)) {
257249
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
258250
}
251+
if (null === $this->values) {
252+
$this->initialize();
253+
}
259254

260255
return !isset($this->values[$key]) && $this->fallbackPool->deleteItem($key);
261256
}
@@ -265,10 +260,6 @@ public function deleteItem($key)
265260
*/
266261
public function deleteItems(array $keys)
267262
{
268-
if (null === $this->values) {
269-
$this->initialize();
270-
}
271-
272263
$deleted = true;
273264
$fallbackKeys = array();
274265

@@ -283,6 +274,9 @@ public function deleteItems(array $keys)
283274
$fallbackKeys[] = $key;
284275
}
285276
}
277+
if (null === $this->values) {
278+
$this->initialize();
279+
}
286280

287281
if ($fallbackKeys) {
288282
$deleted = $this->fallbackPool->deleteItems($fallbackKeys) && $deleted;
@@ -328,7 +322,7 @@ public function commit()
328322
*/
329323
private function initialize()
330324
{
331-
$this->values = @(include $this->file) ?: array();
325+
$this->values = file_exists($this->file) ? (include $this->file ?: array()) : array();
332326
}
333327

334328
/**

0 commit comments

Comments
 (0)
0