Skip to content

Commit 9ddb6af

Browse files
committed
Merge pull request #29 from clue-labs/compat
[RFC] Improve compatibility with legacy versions
2 parents d7e6889 + 2a4a7c9 commit 9ddb6af

5 files changed

Lines changed: 22 additions & 21 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: php
22

33
php:
4+
- 5.3
45
- 5.4
56
- 5.5
67
- 5.6

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"keywords": ["stream", "pipe"],
55
"license": "MIT",
66
"require": {
7-
"php": ">=5.4.0",
8-
"evenement/evenement": "^2.0"
7+
"php": ">=5.3.8",
8+
"evenement/evenement": "^2.0|^1.0"
99
},
1010
"require-dev": {
11-
"react/event-loop": "^0.4",
12-
"react/promise": "^2.0"
11+
"react/event-loop": "^0.4|^0.3",
12+
"react/promise": "^2.0|^1.0"
1313
},
1414
"suggest": {
1515
"react/event-loop": "^0.4",

src/Buffer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function close()
7272
$this->listening = false;
7373
$this->data = '';
7474

75-
$this->emit('close', [$this]);
75+
$this->emit('close', array($this));
7676
}
7777

7878
public function handleWrite()
@@ -112,7 +112,7 @@ public function handleWrite()
112112

113113
$len = strlen($this->data);
114114
if ($len >= $this->softLimit && $len - $sent < $this->softLimit) {
115-
$this->emit('drain', [$this]);
115+
$this->emit('drain', array($this));
116116
}
117117

118118
$this->data = (string) substr($this->data, $sent);
@@ -121,7 +121,7 @@ public function handleWrite()
121121
$this->loop->removeWriteStream($this->stream);
122122
$this->listening = false;
123123

124-
$this->emit('full-drain', [$this]);
124+
$this->emit('full-drain', array($this));
125125
}
126126
}
127127

src/Stream.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ public function __construct($stream, LoopInterface $loop)
3838
$this->loop = $loop;
3939
$this->buffer = new Buffer($this->stream, $this->loop);
4040

41-
$this->buffer->on('error', function ($error) {
42-
$this->emit('error', array($error, $this));
43-
$this->close();
41+
$that = $this;
42+
43+
$this->buffer->on('error', function ($error) use ($that) {
44+
$that->emit('error', array($error, $that));
45+
$that->close();
4446
});
4547

46-
$this->buffer->on('drain', function () {
47-
$this->emit('drain', array($this));
48+
$this->buffer->on('drain', function () use ($that) {
49+
$that->emit('drain', array($that));
4850
});
4951

5052
$this->resume();
@@ -112,9 +114,7 @@ public function end($data = null)
112114
$this->readable = false;
113115
$this->writable = false;
114116

115-
$this->buffer->on('close', function () {
116-
$this->close();
117-
});
117+
$this->buffer->on('close', array($this, 'close'));
118118

119119
$this->buffer->end($data);
120120
}

tests/StreamIntegrationTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ class StreamIntegrationTest extends TestCase
99
{
1010
public function loopProvider()
1111
{
12-
return [
13-
[function() { return true; }, function() { return new rel\StreamSelectLoop; }],
14-
[function() { return function_exists('event_base_new'); }, function() { return new rel\LibEventLoop; }],
15-
[function() { return class_exists('libev\EventLoop'); }, function() { return new rel\LibEvLoop; }],
16-
[function() { return class_exists('EventBase'); }, function() { return new rel\ExtEventLoop; }]
17-
];
12+
return array(
13+
array(function() { return true; }, function() { return new rel\StreamSelectLoop; }),
14+
array(function() { return function_exists('event_base_new'); }, function() { return new rel\LibEventLoop; }),
15+
array(function() { return class_exists('libev\EventLoop'); }, function() { return new rel\LibEvLoop; }),
16+
array(function() { return class_exists('EventBase'); }, function() { return new rel\ExtEventLoop; })
17+
);
1818
}
1919

2020
/**

0 commit comments

Comments
 (0)