From b76d4ea95f284e1cc11dedde690d1cc3714ec276 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 18 Dec 2018 14:39:36 +0100 Subject: [PATCH] [Cache] fix bad optim --- .../Component/Cache/Adapter/PhpFilesAdapter.php | 6 +++--- src/Symfony/Component/Cache/Simple/PhpFilesCache.php | 6 +++--- src/Symfony/Component/Cache/Traits/PhpFilesTrait.php | 10 ++++++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php index 1f4e05e176..10938a0a9e 100644 --- a/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php @@ -31,8 +31,8 @@ class PhpFilesAdapter extends AbstractAdapter implements PruneableInterface self::$startTime = self::$startTime ?? $_SERVER['REQUEST_TIME'] ?? time(); parent::__construct('', $defaultLifetime); $this->init($namespace, $directory); - - $e = new \Exception(); - $this->includeHandler = function () use ($e) { throw $e; }; + $this->includeHandler = static function ($type, $msg, $file, $line) { + throw new \ErrorException($msg, 0, $type, $file, $line); + }; } } diff --git a/src/Symfony/Component/Cache/Simple/PhpFilesCache.php b/src/Symfony/Component/Cache/Simple/PhpFilesCache.php index 19ac8b4152..37432c5af8 100644 --- a/src/Symfony/Component/Cache/Simple/PhpFilesCache.php +++ b/src/Symfony/Component/Cache/Simple/PhpFilesCache.php @@ -31,8 +31,8 @@ class PhpFilesCache extends AbstractCache implements PruneableInterface self::$startTime = self::$startTime ?? $_SERVER['REQUEST_TIME'] ?? time(); parent::__construct('', $defaultLifetime); $this->init($namespace, $directory); - - $e = new \Exception(); - $this->includeHandler = function () use ($e) { throw $e; }; + $this->includeHandler = static function ($type, $msg, $file, $line) { + throw new \ErrorException($msg, 0, $type, $file, $line); + }; } } diff --git a/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php b/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php index 4dacec8cfc..636ad3d99b 100644 --- a/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php +++ b/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php @@ -54,7 +54,11 @@ trait PhpFilesTrait set_error_handler($this->includeHandler); try { foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { - list($expiresAt) = include $file; + try { + list($expiresAt) = include $file; + } catch (\ErrorException $e) { + $expiresAt = $time; + } if ($time >= $expiresAt) { $pruned = $this->doUnlink($file) && !file_exists($file) && $pruned; @@ -111,7 +115,7 @@ trait PhpFilesTrait if ($now >= $expiresAt) { unset($this->values[$id], $missingIds[$k]); } - } catch (\Exception $e) { + } catch (\ErrorException $e) { unset($missingIds[$k]); } } @@ -137,6 +141,8 @@ trait PhpFilesTrait try { $file = $this->files[$id] ?? $this->files[$id] = $this->getFile($id); list($expiresAt, $value) = include $file; + } catch (\ErrorException $e) { + return false; } finally { restore_error_handler(); }