Skip to content

Commit

Permalink
Merge pull request #104 from php-http/avoid-bc-break
Browse files Browse the repository at this point in the history
trigger_error instead of exceptions
  • Loading branch information
dbu committed Nov 1, 2018
2 parents 044735d + 8c225d2 commit b159ffe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
19 changes: 13 additions & 6 deletions src/Encoding/FilteredStream.php
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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()
{
Expand All @@ -174,15 +179,17 @@ 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();
}

/**
* {@inheritdoc}
*/
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);
}

/**
Expand Down

0 comments on commit b159ffe

Please sign in to comment.