From 8c225d2a54d7525523cab34c8ae3d75a151fab4a Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 30 Oct 2018 08:36:52 +0100 Subject: [PATCH] trigger_error instead of exceptions --- CHANGELOG.md | 8 ++++++++ src/Encoding/FilteredStream.php | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a4fa70..48319fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +## [1.7.2] - 2018-10-30 + +### Fixed + +- FilteredStream uses `@trigger_error` instead of throwing exceptions to not + break careless users. You still need to fix your stream code to respect + `isSeekable`. Seeking does not work as expected, and we will add exceptions + in version 2. ## [1.7.1] - 2018-10-29 diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index 26c40ff..7e5713e 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -15,7 +15,10 @@ abstract class FilteredStream implements StreamInterface { const BUFFER_SIZE = 8192; - use StreamDecorator; + use StreamDecorator { + rewind as private doRewind; + seek as private doSeek; + } /** * @var callable @@ -146,11 +149,11 @@ public function getContents() } /** - * {@inheritdoc} + * Always returns null because we can't tell the size of a stream when we filter. */ public function getSize() { - return; + return null; } /** @@ -162,7 +165,9 @@ public function __toString() } /** - * {@inheritdoc} + * Filtered streams are not seekable. + * + * We would need to buffer and process everything to allow seeking. */ public function isSeekable() { @@ -174,7 +179,8 @@ public function isSeekable() */ public function rewind() { - throw new \RuntimeException('Cannot rewind a filtered stream'); + @trigger_error('Filtered streams are not seekable. This method will start raising an exception in the next major version', E_USER_DEPRECATED); + $this->doRewind(); } /** @@ -182,7 +188,8 @@ public function rewind() */ public function seek($offset, $whence = SEEK_SET) { - throw new \RuntimeException('Cannot seek a filtered stream'); + @trigger_error('Filtered streams are not seekable. This method will start raising an exception in the next major version', E_USER_DEPRECATED); + $this->doSeek($offset, $whence); } /**