From b9e22b4da43295b89f9deac1c6d3c43afb9ca282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Mon, 7 Aug 2017 17:26:54 +0200 Subject: [PATCH] [ticket/15305] Simulate streams if they are not implemented PHPBB3-15305 --- phpBB/phpbb/storage/storage.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/storage/storage.php b/phpBB/phpbb/storage/storage.php index 3d7052bc84..93d9208cc7 100644 --- a/phpBB/phpbb/storage/storage.php +++ b/phpBB/phpbb/storage/storage.php @@ -160,7 +160,22 @@ class storage */ public function read_stream($path) { - $this->get_adapter()->read_stream($path); + $stream = null; + $adapter = $this->get_adapter(); + + if ($adapter instanceof stream_interface) + { + $stream = $adapter->read_stream($path); + } + else + { + // Simulate the stream + $stream = tmpfile(); + fwrite($stream, $adapter->get_contents($path)); + rewind($stream); + } + + return $stream; } /** @@ -173,6 +188,16 @@ class storage */ public function write_stream($path, $resource) { - $this->get_adapter()->write_stream($path, $resource); + $adapter = $this->get_adapter(); + + if ($adapter instanceof stream_interface) + { + $adapter>write_stream($path, $resource); + } + else + { + // Simulate the stream + $adapter->put_contents($path, stream_get_contents($resource)); + } } }