diff --git a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperForCacheStorage.php b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperForCacheStorage.php index 2e7702a..ba8a743 100644 --- a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperForCacheStorage.php +++ b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperForCacheStorage.php @@ -6,6 +6,7 @@ */ namespace Drupal\Core\StreamWrapper; + use Drupal\Core\PhpStorage\CacheStorage; /** @@ -23,19 +24,21 @@ class StreamWrapperForCacheStorage { protected static $storage; /** + * The (fake) modified timestamp of the file this class wraps. + * * @var int */ protected static $mtime; /** - * Stream context resource. + * Stream context resource set by PHP and ignored by this class. * * @var resource */ public $context = NULL; /** - * A generic resource handle. + * The file handle of the in-memory stream. * * @var resource */ @@ -55,7 +58,12 @@ public static function init(CacheStorage $storage, $mtime) { static::$mtime = $mtime; } - public function stream_close () { + public function stream_open($path) { + static::$handle = static::$storage->open($path); + return (bool) static::$handle; + } + + public function stream_close() { return fclose(static::$handle); } @@ -63,20 +71,23 @@ public function stream_eof() { return feof(static::$handle); } - public function stream_flush() { - return fflush(static::$handle); - } - - public function stream_open($path) { - static::$handle = static::$storage->open($path); - return (bool) static::$handle; - } - public function stream_read($count) { return fread(static::$handle, $count); } + public function stream_flush() { + // This is called on every file close even if there is nothing to flush + // and we do not write anything so we do not actually need to flush + // anything. + return TRUE; + } + public function stream_stat() { + // When the file is not yet opcode cached, the mtime is read through + // stream_stat() during file compile. The stat() results are not dependent + // on the position in the file and we know which file we are working on so + // using $handle is not necessary and just calling url_stat() to return the + // fake mtime is both correct and necessary. return static::url_stat(); }