Skip to content

Commit e99b556

Browse files
committed
Remove public $stream property from all resource streams
1 parent f4d90ca commit e99b556

6 files changed

Lines changed: 9 additions & 54 deletions

File tree

README.md

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -753,12 +753,6 @@ Once the constructor is called with a valid stream resource, this class will
753753
take care of the underlying stream resource.
754754
You SHOULD only use its public API and SHOULD NOT interfere with the underlying
755755
stream resource manually.
756-
Should you need to access the underlying stream resource, you can use the public
757-
`$stream` property like this:
758-
759-
```php
760-
var_dump(stream_get_meta_data($stream->stream));
761-
```
762756

763757
The `$bufferSize` property controls the maximum buffer size in bytes to read
764758
at once from the stream.
@@ -819,12 +813,6 @@ Once the constructor is called with a valid stream resource, this class will
819813
take care of the underlying stream resource.
820814
You SHOULD only use its public API and SHOULD NOT interfere with the underlying
821815
stream resource manually.
822-
Should you need to access the underlying stream resource, you can use the public
823-
`$stream` property like this:
824-
825-
```php
826-
var_dump(stream_get_meta_data($stream->stream));
827-
```
828816

829817
Any `write()` calls to this class will not be performaned instantly, but will
830818
be performaned asynchronously, once the EventLoop reports the stream resource is
@@ -885,12 +873,6 @@ Once the constructor is called with a valid stream resource, this class will
885873
take care of the underlying stream resource.
886874
You SHOULD only use its public API and SHOULD NOT interfere with the underlying
887875
stream resource manually.
888-
Should you need to access the underlying stream resource, you can use the public
889-
`$stream` property like this:
890-
891-
```php
892-
var_dump(stream_get_meta_data($stream->stream));
893-
```
894876

895877
The `$bufferSize` property controls the maximum buffer size in bytes to read
896878
at once from the stream.

examples/benchmark-throughput.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
$info->write('piping from ' . $if . ' to ' . $of . ' (for max ' . $t . ' second(s)) ...'. PHP_EOL);
2222

2323
// setup input and output streams and pipe inbetween
24-
$in = new React\Stream\ReadableResourceStream(fopen($if, 'r'), $loop);
24+
$fh = fopen($if, 'r');
25+
$in = new React\Stream\ReadableResourceStream($fh, $loop);
2526
$out = new React\Stream\WritableResourceStream(fopen($of, 'w'), $loop);
2627
$in->pipe($out);
2728

@@ -32,11 +33,11 @@
3233
});
3334

3435
// print stream position once stream closes
35-
$in->on('close', function () use ($in, $start, $timeout, $info) {
36+
$in->on('close', function () use ($fh, $start, $timeout, $info) {
3637
$t = microtime(true) - $start;
3738
$timeout->cancel();
3839

39-
$bytes = ftell($in->stream);
40+
$bytes = ftell($fh);
4041

4142
$info->write('read ' . $bytes . ' byte(s) in ' . round($t, 3) . ' second(s) => ' . round($bytes / 1024 / 1024 / $t, 1) . ' MiB/s' . PHP_EOL);
4243
$info->write('peak memory usage of ' . round(memory_get_peak_usage(true) / 1024 / 1024, 1) . ' MiB' . PHP_EOL);

src/DuplexResourceStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DuplexResourceStream extends EventEmitter implements DuplexStreamInterface
2626
*/
2727
public $bufferSize = 65536;
2828

29-
public $stream;
29+
private $stream;
3030
protected $readable = true;
3131
protected $writable = true;
3232
protected $closing = false;

src/ReadableResourceStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ReadableResourceStream extends EventEmitter implements ReadableStreamInter
3131
/**
3232
* @var resource
3333
*/
34-
public $stream;
34+
private $stream;
3535

3636
private $closed = false;
3737
private $loop;

src/WritableResourceStream.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class WritableResourceStream extends EventEmitter implements WritableStreamInterface
99
{
10-
public $stream;
10+
private $stream;
1111
public $softLimit = 65536;
1212

1313
private $listening = false;
@@ -118,9 +118,7 @@ public function handleWrite()
118118
// Should this turn out to be a permanent error later, it will eventually
119119
// send *nothing* and we can detect this.
120120
if ($sent === 0 || $sent === false) {
121-
if ($error === null) {
122-
$error = new \RuntimeException('Send failed');
123-
} else {
121+
if ($error !== null) {
124122
$error = new \ErrorException(
125123
$error['message'],
126124
0,
@@ -130,7 +128,7 @@ public function handleWrite()
130128
);
131129
}
132130

133-
$this->emit('error', array(new \RuntimeException('Unable to write to stream: ' . $error->getMessage(), 0, $error)));
131+
$this->emit('error', array(new \RuntimeException('Unable to write to stream: ' . ($error !== null ? $error->getMessage() : 'Unknown error'), 0, $error)));
134132
$this->close();
135133

136134
return;

tests/WritableStreamResourceTest.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -138,32 +138,6 @@ public function testWriteReturnsFalseWhenWritableResourceStreamIsExactlyFull()
138138
$this->assertFalse($buffer->write("foo"));
139139
}
140140

141-
/**
142-
* @covers React\Stream\WritableResourceStream::write
143-
* @covers React\Stream\WritableResourceStream::handleWrite
144-
*/
145-
public function testWriteEmitsErrorWhenResourceIsNotWritable()
146-
{
147-
if (defined('HHVM_VERSION')) {
148-
// via https://github.com/reactphp/stream/pull/52/files#r75493076
149-
$this->markTestSkipped('HHVM allows writing to read-only memory streams');
150-
}
151-
152-
$stream = fopen('php://temp', 'r+');
153-
$loop = $this->createLoopMock();
154-
155-
$buffer = new WritableResourceStream($stream, $loop);
156-
157-
// nasty hack to replace with reaad-only stream resource
158-
$buffer->stream = fopen('php://temp', 'r');
159-
160-
$buffer->on('error', $this->expectCallableOnce());
161-
//$buffer->on('close', $this->expectCallableOnce());
162-
163-
$buffer->write('hello');
164-
$buffer->handleWrite();
165-
}
166-
167141
/**
168142
* @covers React\Stream\WritableResourceStream::write
169143
* @covers React\Stream\WritableResourceStream::handleWrite

0 commit comments

Comments
 (0)