Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: drop $loop input parameters in favor of Loop::get() #176

Open
wants to merge 5 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ jobs:
- 7.3
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
- 5.3
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
],
"require": {
"php": ">=5.3.8",
"php": ">=7.1",
"react/event-loop": "^1.2",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0"
},
Expand Down
13 changes: 4 additions & 9 deletions src/DuplexResourceStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@

use Evenement\EventEmitter;
use React\EventLoop\Loop;
use React\EventLoop\LoopInterface;
use InvalidArgumentException;

final class DuplexResourceStream extends EventEmitter implements DuplexStreamInterface
{
private $stream;

/** @var LoopInterface */
private $loop;

/**
* Controls the maximum buffer size in bytes to read at once from the stream.
*
Expand All @@ -38,7 +34,7 @@ final class DuplexResourceStream extends EventEmitter implements DuplexStreamInt
private $closing = false;
private $listening = false;

public function __construct($stream, LoopInterface $loop = null, $readChunkSize = null, WritableStreamInterface $buffer = null)
public function __construct($stream, $readChunkSize = null, WritableStreamInterface $buffer = null)
{
if (!\is_resource($stream) || \get_resource_type($stream) !== "stream") {
throw new InvalidArgumentException('First parameter must be a valid stream resource');
Expand Down Expand Up @@ -69,11 +65,10 @@ public function __construct($stream, LoopInterface $loop = null, $readChunkSize
}

if ($buffer === null) {
$buffer = new WritableResourceStream($stream, $loop);
$buffer = new WritableResourceStream($stream);
}

$this->stream = $stream;
$this->loop = $loop ?: Loop::get();
$this->bufferSize = ($readChunkSize === null) ? 65536 : (int)$readChunkSize;
$this->buffer = $buffer;

Expand Down Expand Up @@ -105,15 +100,15 @@ public function isWritable()
public function pause()
{
if ($this->listening) {
$this->loop->removeReadStream($this->stream);
Loop::removeReadStream($this->stream);
$this->listening = false;
}
}

public function resume()
{
if (!$this->listening && $this->readable) {
$this->loop->addReadStream($this->stream, array($this, 'handleData'));
Loop::addReadStream($this->stream, array($this, 'handleData'));
$this->listening = true;
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/ReadableResourceStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Evenement\EventEmitter;
use React\EventLoop\Loop;
use React\EventLoop\LoopInterface;
use InvalidArgumentException;

final class ReadableResourceStream extends EventEmitter implements ReadableStreamInterface
Expand All @@ -14,9 +13,6 @@ final class ReadableResourceStream extends EventEmitter implements ReadableStrea
*/
private $stream;

/** @var LoopInterface */
private $loop;

/**
* Controls the maximum buffer size in bytes to read at once from the stream.
*
Expand All @@ -40,7 +36,7 @@ final class ReadableResourceStream extends EventEmitter implements ReadableStrea
private $closed = false;
private $listening = false;

public function __construct($stream, LoopInterface $loop = null, $readChunkSize = null)
public function __construct($stream, $readChunkSize = null)
{
if (!\is_resource($stream) || \get_resource_type($stream) !== "stream") {
throw new InvalidArgumentException('First parameter must be a valid stream resource');
Expand Down Expand Up @@ -71,7 +67,6 @@ public function __construct($stream, LoopInterface $loop = null, $readChunkSize
}

$this->stream = $stream;
$this->loop = $loop ?: Loop::get();
$this->bufferSize = ($readChunkSize === null) ? 65536 : (int)$readChunkSize;

$this->resume();
Expand All @@ -85,15 +80,15 @@ public function isReadable()
public function pause()
{
if ($this->listening) {
$this->loop->removeReadStream($this->stream);
Loop::removeReadStream($this->stream);
$this->listening = false;
}
}

public function resume()
{
if (!$this->listening && !$this->closed) {
$this->loop->addReadStream($this->stream, array($this, 'handleData'));
Loop::addReadStream($this->stream, array($this, 'handleData'));
$this->listening = true;
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/WritableResourceStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ final class WritableResourceStream extends EventEmitter implements WritableStrea
{
private $stream;

/** @var LoopInterface */
private $loop;

/**
* @var int
*/
Expand All @@ -28,7 +25,7 @@ final class WritableResourceStream extends EventEmitter implements WritableStrea
private $closed = false;
private $data = '';

public function __construct($stream, LoopInterface $loop = null, $writeBufferSoftLimit = null, $writeChunkSize = null)
public function __construct($stream, $writeBufferSoftLimit = null, $writeChunkSize = null)
{
if (!\is_resource($stream) || \get_resource_type($stream) !== "stream") {
throw new \InvalidArgumentException('First parameter must be a valid stream resource');
Expand All @@ -47,7 +44,6 @@ public function __construct($stream, LoopInterface $loop = null, $writeBufferSof
}

$this->stream = $stream;
$this->loop = $loop ?: Loop::get();
$this->softLimit = ($writeBufferSoftLimit === null) ? 65536 : (int)$writeBufferSoftLimit;
$this->writeChunkSize = ($writeChunkSize === null) ? -1 : (int)$writeChunkSize;
}
Expand All @@ -68,7 +64,7 @@ public function write($data)
if (!$this->listening && $this->data !== '') {
$this->listening = true;

$this->loop->addWriteStream($this->stream, array($this, 'handleWrite'));
Loop::addWriteStream($this->stream, array($this, 'handleWrite'));
}

return !isset($this->data[$this->softLimit - 1]);
Expand Down Expand Up @@ -97,7 +93,7 @@ public function close()

if ($this->listening) {
$this->listening = false;
$this->loop->removeWriteStream($this->stream);
Loop::removeWriteStream($this->stream);
}

$this->closed = true;
Expand Down Expand Up @@ -155,7 +151,7 @@ public function handleWrite()
if ($this->data === '') {
// stop waiting for resource to be writable
if ($this->listening) {
$this->loop->removeWriteStream($this->stream);
Loop::removeWriteStream($this->stream);
$this->listening = false;
}

Expand Down
Loading