X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdoctrine%2Fcache%2Flib%2FDoctrine%2FCommon%2FCache%2FPhpFileCache.php;fp=vendor%2Fdoctrine%2Fcache%2Flib%2FDoctrine%2FCommon%2FCache%2FPhpFileCache.php;h=d243ab6c74b5de064c37d215ff07c2c5126ba807;hp=5e7519674e3e50414772f5bd3473870f53595d12;hb=5e458ff8cb4924fd5fa03b80d8edfcc52fe43479;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5 diff --git a/vendor/doctrine/cache/lib/Doctrine/Common/Cache/PhpFileCache.php b/vendor/doctrine/cache/lib/Doctrine/Common/Cache/PhpFileCache.php index 5e7519674..d243ab6c7 100644 --- a/vendor/doctrine/cache/lib/Doctrine/Common/Cache/PhpFileCache.php +++ b/vendor/doctrine/cache/lib/Doctrine/Common/Cache/PhpFileCache.php @@ -29,12 +29,22 @@ class PhpFileCache extends FileCache { const EXTENSION = '.doctrinecache.php'; + /** + * @var callable + * + * This is cached in a local static variable to avoid instantiating a closure each time we need an empty handler + */ + private static $emptyErrorHandler; + /** * {@inheritdoc} */ public function __construct($directory, $extension = self::EXTENSION, $umask = 0002) { parent::__construct($directory, $extension, $umask); + + self::$emptyErrorHandler = function () { + }; } /** @@ -44,7 +54,7 @@ class PhpFileCache extends FileCache { $value = $this->includeFileForId($id); - if (! $value) { + if ($value === null) { return false; } @@ -62,7 +72,7 @@ class PhpFileCache extends FileCache { $value = $this->includeFileForId($id); - if (! $value) { + if ($value === null) { return false; } @@ -78,23 +88,20 @@ class PhpFileCache extends FileCache $lifeTime = time() + $lifeTime; } - if (is_object($data) && ! method_exists($data, '__set_state')) { - throw new \InvalidArgumentException( - "Invalid argument given, PhpFileCache only allows objects that implement __set_state() " . - "and fully support var_export(). You can use the FilesystemCache to save arbitrary object " . - "graphs using serialize()/deserialize()." - ); - } - $filename = $this->getFilename($id); - $value = array( + $value = [ 'lifetime' => $lifeTime, 'data' => $data - ); - - $value = var_export($value, true); - $code = sprintf('writeFile($filename, $code); } @@ -102,17 +109,21 @@ class PhpFileCache extends FileCache /** * @param string $id * - * @return array|false + * @return array|null */ - private function includeFileForId($id) + private function includeFileForId(string $id) : ?array { $fileName = $this->getFilename($id); // note: error suppression is still faster than `file_exists`, `is_file` and `is_readable` - $value = @include $fileName; + set_error_handler(self::$emptyErrorHandler); + + $value = include $fileName; + + restore_error_handler(); if (! isset($value['lifetime'])) { - return false; + return null; } return $value;