Skip to content

Commit e4313ea

Browse files
committed
Update to require PHP 7.1+
1 parent 751374f commit e4313ea

21 files changed

+109
-258
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ jobs:
1919
- 7.3
2020
- 7.2
2121
- 7.1
22-
- 7.0
23-
- 5.6
24-
- 5.5
25-
- 5.4
26-
- 5.3
2722
steps:
2823
- uses: actions/checkout@v4
2924
- uses: shivammathur/setup-php@v2
@@ -52,23 +47,3 @@ jobs:
5247
- run: composer install
5348
- run: vendor/bin/phpunit --coverage-text
5449
- run: time php examples/91-benchmark-throughput.php
55-
56-
PHPUnit-hhvm:
57-
name: PHPUnit (HHVM)
58-
runs-on: ubuntu-22.04
59-
continue-on-error: true
60-
steps:
61-
- uses: actions/checkout@v4
62-
- run: cp "$(which composer)" composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
63-
- name: Run hhvm composer.phar install
64-
uses: docker://hhvm/hhvm:3.30-lts-latest
65-
with:
66-
args: hhvm composer.phar install
67-
- name: Run hhvm vendor/bin/phpunit
68-
uses: docker://hhvm/hhvm:3.30-lts-latest
69-
with:
70-
args: hhvm vendor/bin/phpunit
71-
- name: Run time hhvm examples/91-benchmark-throughput.php
72-
uses: docker://hhvm/hhvm:3.30-lts-latest
73-
with:
74-
args: bash -c "time hhvm examples/91-benchmark-throughput.php"

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ By default, this will call `end()` on the destination stream once the
353353
source stream emits an `end` event. This can be disabled like this:
354354

355355
```php
356-
$source->pipe($dest, array('end' => false));
356+
$source->pipe($dest, ['end' => false]);
357357
```
358358

359359
Note that this only applies to the `end` event.
@@ -1126,7 +1126,7 @@ $through = new ThroughStream(function ($data) {
11261126
});
11271127
$through->on('data', $this->expectCallableOnceWith("[2, true]\n"));
11281128

1129-
$through->write(array(2, true));
1129+
$through->write([2, true]);
11301130
```
11311131

11321132
The callback function is allowed to throw an `Exception`. In this case,
@@ -1217,9 +1217,8 @@ composer require react/stream:^3@dev
12171217
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
12181218

12191219
This project aims to run on any platform and thus does not require any PHP
1220-
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and HHVM.
1221-
It's *highly recommended to use PHP 7+* for this project due to its vast
1222-
performance improvements.
1220+
extensions and supports running on PHP 7.1 through current PHP 8+.
1221+
It's *highly recommended to use the latest supported PHP version* for this project.
12231222

12241223
## Tests
12251224

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
}
2727
],
2828
"require": {
29-
"php": ">=5.3.8",
29+
"php": ">=7.1",
3030
"react/event-loop": "^1.2",
3131
"evenement/evenement": "^3.0 || ^2.0 || ^1.0"
3232
},
3333
"require-dev": {
34-
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36",
34+
"phpunit/phpunit": "^9.6 || ^7.5",
3535
"clue/stream-filter": "~1.2"
3636
},
3737
"autoload": {

phpunit.xml.legacy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
66
bootstrap="vendor/autoload.php"
77
colors="true">
88
<testsuites>

src/CompositeStream.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public function __construct(ReadableStreamInterface $readable, WritableStreamInt
2020
return;
2121
}
2222

23-
Util::forwardEvents($this->readable, $this, array('data', 'end', 'error'));
24-
Util::forwardEvents($this->writable, $this, array('drain', 'error', 'pipe'));
23+
Util::forwardEvents($this->readable, $this, ['data', 'end', 'error']);
24+
Util::forwardEvents($this->writable, $this, ['drain', 'error', 'pipe']);
2525

26-
$this->readable->on('close', array($this, 'close'));
27-
$this->writable->on('close', array($this, 'close'));
26+
$this->readable->on('close', [$this, 'close']);
27+
$this->writable->on('close', [$this, 'close']);
2828
}
2929

3030
public function isReadable()
@@ -46,7 +46,7 @@ public function resume()
4646
$this->readable->resume();
4747
}
4848

49-
public function pipe(WritableStreamInterface $dest, array $options = array())
49+
public function pipe(WritableStreamInterface $dest, array $options = [])
5050
{
5151
return Util::pipe($this, $dest, $options);
5252
}

src/DuplexResourceStream.php

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,9 @@ public function __construct($stream, LoopInterface $loop = null, $readChunkSize
5959
// Use unbuffered read operations on the underlying stream resource.
6060
// Reading chunks from the stream may otherwise leave unread bytes in
6161
// PHP's stream buffers which some event loop implementations do not
62-
// trigger events on (edge triggered).
63-
// This does not affect the default event loop implementation (level
64-
// triggered), so we can ignore platforms not supporting this (HHVM).
65-
// Pipe streams (such as STDIN) do not seem to require this and legacy
66-
// PHP versions cause SEGFAULTs on unbuffered pipe streams, so skip this.
67-
if (\function_exists('stream_set_read_buffer') && !$this->isLegacyPipe($stream)) {
68-
\stream_set_read_buffer($stream, 0);
69-
}
62+
// trigger events on (edge triggered). This does not affect the default
63+
// event loop implementation (level triggered).
64+
\stream_set_read_buffer($stream, 0);
7065

7166
if ($buffer === null) {
7267
$buffer = new WritableResourceStream($stream, $loop);
@@ -80,10 +75,10 @@ public function __construct($stream, LoopInterface $loop = null, $readChunkSize
8075
$that = $this;
8176

8277
$this->buffer->on('error', function ($error) use ($that) {
83-
$that->emit('error', array($error));
78+
$that->emit('error', [$error]);
8479
});
8580

86-
$this->buffer->on('close', array($this, 'close'));
81+
$this->buffer->on('close', [$this, 'close']);
8782

8883
$this->buffer->on('drain', function () use ($that) {
8984
$that->emit('drain');
@@ -113,7 +108,7 @@ public function pause()
113108
public function resume()
114109
{
115110
if (!$this->listening && $this->readable) {
116-
$this->loop->addReadStream($this->stream, array($this, 'handleData'));
111+
$this->loop->addReadStream($this->stream, [$this, 'handleData']);
117112
$this->listening = true;
118113
}
119114
}
@@ -163,7 +158,7 @@ public function end($data = null)
163158
$this->buffer->end($data);
164159
}
165160

166-
public function pipe(WritableStreamInterface $dest, array $options = array())
161+
public function pipe(WritableStreamInterface $dest, array $options = [])
167162
{
168163
return Util::pipe($this, $dest, $options);
169164
}
@@ -187,41 +182,17 @@ public function handleData($stream)
187182
\restore_error_handler();
188183

189184
if ($error !== null) {
190-
$this->emit('error', array(new \RuntimeException('Unable to read from stream: ' . $error->getMessage(), 0, $error)));
185+
$this->emit('error', [new \RuntimeException('Unable to read from stream: ' . $error->getMessage(), 0, $error)]);
191186
$this->close();
192187
return;
193188
}
194189

195190
if ($data !== '') {
196-
$this->emit('data', array($data));
191+
$this->emit('data', [$data]);
197192
} elseif (\feof($this->stream)) {
198193
// no data read => we reached the end and close the stream
199194
$this->emit('end');
200195
$this->close();
201196
}
202197
}
203-
204-
/**
205-
* Returns whether this is a pipe resource in a legacy environment
206-
*
207-
* This works around a legacy PHP bug (#61019) that was fixed in PHP 5.4.28+
208-
* and PHP 5.5.12+ and newer.
209-
*
210-
* @param resource $resource
211-
* @return bool
212-
* @link https://github.com/reactphp/child-process/issues/40
213-
*
214-
* @codeCoverageIgnore
215-
*/
216-
private function isLegacyPipe($resource)
217-
{
218-
if (\PHP_VERSION_ID < 50428 || (\PHP_VERSION_ID >= 50500 && \PHP_VERSION_ID < 50512)) {
219-
$meta = \stream_get_meta_data($resource);
220-
221-
if (isset($meta['stream_type']) && $meta['stream_type'] === 'STDIO') {
222-
return true;
223-
}
224-
}
225-
return false;
226-
}
227198
}

src/ReadableResourceStream.php

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,9 @@ public function __construct($stream, LoopInterface $loop = null, $readChunkSize
6161
// Use unbuffered read operations on the underlying stream resource.
6262
// Reading chunks from the stream may otherwise leave unread bytes in
6363
// PHP's stream buffers which some event loop implementations do not
64-
// trigger events on (edge triggered).
65-
// This does not affect the default event loop implementation (level
66-
// triggered), so we can ignore platforms not supporting this (HHVM).
67-
// Pipe streams (such as STDIN) do not seem to require this and legacy
68-
// PHP versions cause SEGFAULTs on unbuffered pipe streams, so skip this.
69-
if (\function_exists('stream_set_read_buffer') && !$this->isLegacyPipe($stream)) {
70-
\stream_set_read_buffer($stream, 0);
71-
}
64+
// trigger events on (edge triggered). This does not affect the default
65+
// event loop implementation (level triggered).
66+
\stream_set_read_buffer($stream, 0);
7267

7368
$this->stream = $stream;
7469
$this->loop = $loop ?: Loop::get();
@@ -93,12 +88,12 @@ public function pause()
9388
public function resume()
9489
{
9590
if (!$this->listening && !$this->closed) {
96-
$this->loop->addReadStream($this->stream, array($this, 'handleData'));
91+
$this->loop->addReadStream($this->stream, [$this, 'handleData']);
9792
$this->listening = true;
9893
}
9994
}
10095

101-
public function pipe(WritableStreamInterface $dest, array $options = array())
96+
public function pipe(WritableStreamInterface $dest, array $options = [])
10297
{
10398
return Util::pipe($this, $dest, $options);
10499
}
@@ -139,41 +134,17 @@ public function handleData()
139134
\restore_error_handler();
140135

141136
if ($error !== null) {
142-
$this->emit('error', array(new \RuntimeException('Unable to read from stream: ' . $error->getMessage(), 0, $error)));
137+
$this->emit('error', [new \RuntimeException('Unable to read from stream: ' . $error->getMessage(), 0, $error)]);
143138
$this->close();
144139
return;
145140
}
146141

147142
if ($data !== '') {
148-
$this->emit('data', array($data));
143+
$this->emit('data', [$data]);
149144
} elseif (\feof($this->stream)) {
150145
// no data read => we reached the end and close the stream
151146
$this->emit('end');
152147
$this->close();
153148
}
154149
}
155-
156-
/**
157-
* Returns whether this is a pipe resource in a legacy environment
158-
*
159-
* This works around a legacy PHP bug (#61019) that was fixed in PHP 5.4.28+
160-
* and PHP 5.5.12+ and newer.
161-
*
162-
* @param resource $resource
163-
* @return bool
164-
* @link https://github.com/reactphp/child-process/issues/40
165-
*
166-
* @codeCoverageIgnore
167-
*/
168-
private function isLegacyPipe($resource)
169-
{
170-
if (\PHP_VERSION_ID < 50428 || (\PHP_VERSION_ID >= 50500 && \PHP_VERSION_ID < 50512)) {
171-
$meta = \stream_get_meta_data($resource);
172-
173-
if (isset($meta['stream_type']) && $meta['stream_type'] === 'STDIO') {
174-
return true;
175-
}
176-
}
177-
return false;
178-
}
179150
}

src/ReadableStreamInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public function resume();
278278
* source stream emits an `end` event. This can be disabled like this:
279279
*
280280
* ```php
281-
* $source->pipe($dest, array('end' => false));
281+
* $source->pipe($dest, ['end' => false]);
282282
* ```
283283
*
284284
* Note that this only applies to the `end` event.
@@ -322,7 +322,7 @@ public function resume();
322322
* @param array $options
323323
* @return WritableStreamInterface $dest stream as-is
324324
*/
325-
public function pipe(WritableStreamInterface $dest, array $options = array());
325+
public function pipe(WritableStreamInterface $dest, array $options = []);
326326

327327
/**
328328
* Closes the stream (forcefully).

src/ThroughStream.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* });
4949
* $through->on('data', $this->expectCallableOnceWith("[2, true]\n"));
5050
*
51-
* $through->write(array(2, true));
51+
* $through->write([2, true]);
5252
* ```
5353
*
5454
* The callback function is allowed to throw an `Exception`. In this case,
@@ -108,7 +108,7 @@ public function resume()
108108
}
109109
}
110110

111-
public function pipe(WritableStreamInterface $dest, array $options = array())
111+
public function pipe(WritableStreamInterface $dest, array $options = [])
112112
{
113113
return Util::pipe($this, $dest, $options);
114114
}
@@ -133,14 +133,14 @@ public function write($data)
133133
try {
134134
$data = \call_user_func($this->callback, $data);
135135
} catch (\Exception $e) {
136-
$this->emit('error', array($e));
136+
$this->emit('error', [$e]);
137137
$this->close();
138138

139139
return false;
140140
}
141141
}
142142

143-
$this->emit('data', array($data));
143+
$this->emit('data', [$data]);
144144

145145
// emit drain event on next resume if currently paused (throttled)
146146
if ($this->paused) {

src/Util.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class Util
1313
* @return WritableStreamInterface $dest stream as-is
1414
* @see ReadableStreamInterface::pipe() for more details
1515
*/
16-
public static function pipe(ReadableStreamInterface $source, WritableStreamInterface $dest, array $options = array())
16+
public static function pipe(ReadableStreamInterface $source, WritableStreamInterface $dest, array $options = [])
1717
{
1818
// source not readable => NO-OP
1919
if (!$source->isReadable()) {
@@ -27,7 +27,7 @@ public static function pipe(ReadableStreamInterface $source, WritableStreamInter
2727
return $dest;
2828
}
2929

30-
$dest->emit('pipe', array($source));
30+
$dest->emit('pipe', [$source]);
3131

3232
// forward all source data events as $dest->write()
3333
$source->on('data', $dataer = function ($data) use ($source, $dest) {

src/WritableResourceStream.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function write($data)
6868
if (!$this->listening && $this->data !== '') {
6969
$this->listening = true;
7070

71-
$this->loop->addWriteStream($this->stream, array($this, 'handleWrite'));
71+
$this->loop->addWriteStream($this->stream, [$this, 'handleWrite']);
7272
}
7373

7474
return !isset($this->data[$this->softLimit - 1]);
@@ -137,7 +137,7 @@ public function handleWrite()
137137
// Should this turn out to be a permanent error later, it will eventually
138138
// send *nothing* and we can detect this.
139139
if (($sent === 0 || $sent === false) && $error !== null) {
140-
$this->emit('error', array(new \RuntimeException('Unable to write to stream: ' . $error)));
140+
$this->emit('error', [new \RuntimeException('Unable to write to stream: ' . $error)]);
141141
$this->close();
142142

143143
return;

tests/CompositeStreamTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function itShouldReceiveForwardedEvents()
217217
$composite->on('data', $this->expectCallableOnce());
218218
$composite->on('drain', $this->expectCallableOnce());
219219

220-
$readable->emit('data', array('foo'));
220+
$readable->emit('data', ['foo']);
221221
$writable->emit('drain');
222222
}
223223

@@ -241,7 +241,7 @@ public function itShouldHandlePipingCorrectly()
241241

242242
$input = new ThroughStream();
243243
$input->pipe($composite);
244-
$input->emit('data', array('foo'));
244+
$input->emit('data', ['foo']);
245245
}
246246

247247
/** @test */
@@ -262,6 +262,6 @@ public function itShouldForwardPipeCallsToReadableStream()
262262
->with('foo');
263263

264264
$composite->pipe($output);
265-
$readable->emit('data', array('foo'));
265+
$readable->emit('data', ['foo']);
266266
}
267267
}

0 commit comments

Comments
 (0)