Skip to content

Commit 1279cb3

Browse files
committed
Compatiblity with legacy versions
1 parent 38dbd8f commit 1279cb3

File tree

5 files changed

+30
-24
lines changed

5 files changed

+30
-24
lines changed

.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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"keywords": ["socket"],
55
"license": "MIT",
66
"require": {
7-
"php": ">=5.4.0",
8-
"react/dns": "0.4.*",
9-
"react/event-loop": "0.4.*",
10-
"react/stream": "0.4.*",
11-
"react/promise": "~2.0"
7+
"php": ">=5.3.0",
8+
"react/dns": "0.4.*|0.3.*",
9+
"react/event-loop": "0.4.*|0.3.*",
10+
"react/stream": "0.4.*|0.3.*",
11+
"react/promise": "~2.0|~1.1"
1212
},
1313
"autoload": {
1414
"psr-4": {

src/SecureConnector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public function create($host, $port)
3838
);
3939
}
4040

41-
return $this->connector->create($host, $port)->then(function (Stream $stream) use ($context) {
41+
$encryption = $this->streamEncryption;
42+
return $this->connector->create($host, $port)->then(function (Stream $stream) use ($context, $encryption) {
4243
// (unencrypted) TCP/IP connection succeeded
4344

4445
// set required SSL/TLS context options
@@ -47,7 +48,7 @@ public function create($host, $port)
4748
}
4849

4950
// try to enable encryption
50-
return $this->streamEncryption->enable($stream)->then(null, function ($error) use ($stream) {
51+
return $encryption->enable($stream)->then(null, function ($error) use ($stream) {
5152
// establishing encryption failed => close invalid connection and return error
5253
$stream->close();
5354
throw $error;

src/SecureStream.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
use Evenement\EventEmitterTrait;
66
use React\EventLoop\LoopInterface;
7-
use React\Stream\DuplexStreamInterface;
87
use React\Stream\WritableStreamInterface;
98
use React\Stream\Stream;
109
use React\Stream\Util;
1110

12-
class SecureStream extends Stream implements DuplexStreamInterface
11+
class SecureStream extends Stream
1312
{
1413
// use EventEmitterTrait;
1514

@@ -22,18 +21,19 @@ public function __construct(Stream $stream, LoopInterface $loop) {
2221
$this->stream = $stream->stream;
2322
$this->decorating = $stream;
2423
$this->loop = $loop;
24+
$that = $this;
2525

26-
$stream->on('error', function($error) {
27-
$this->emit('error', [$error, $this]);
26+
$stream->on('error', function($error) use ($that) {
27+
$that->emit('error', array($error, $that));
2828
});
29-
$stream->on('end', function() {
30-
$this->emit('end', [$this]);
29+
$stream->on('end', function() use ($that) {
30+
$that->emit('end', array($that));
3131
});
32-
$stream->on('close', function() {
33-
$this->emit('close', [$this]);
32+
$stream->on('close', function() use ($that) {
33+
$that->emit('close', array($that));
3434
});
35-
$stream->on('drain', function() {
36-
$this->emit('drain', [$this]);
35+
$stream->on('drain', function() use ($that) {
36+
$that->emit('drain', array($that));
3737
});
3838

3939
$stream->pause();
@@ -45,7 +45,7 @@ public function handleData($stream)
4545
{
4646
$data = stream_get_contents($stream);
4747

48-
$this->emit('data', [$data, $this]);
48+
$this->emit('data', array($data, $this));
4949

5050
if (!is_resource($stream) || feof($stream)) {
5151
$this->end();
@@ -60,7 +60,7 @@ public function pause()
6060
public function resume()
6161
{
6262
if ($this->isReadable()) {
63-
$this->loop->addReadStream($this->decorating->stream, [$this, 'handleData']);
63+
$this->loop->addReadStream($this->decorating->stream, array($this, 'handleData'));
6464
}
6565
}
6666

src/StreamEncryption.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,20 @@ public function toggle(Stream $stream, $toggle)
7171
// get actual stream socket from stream instance
7272
$socket = $stream->stream;
7373

74-
$toggleCrypto = function () use ($socket, $deferred, $toggle) {
75-
$this->toggleCrypto($socket, $deferred, $toggle);
74+
$that = $this;
75+
$toggleCrypto = function () use ($socket, $deferred, $toggle, $that) {
76+
$that->toggleCrypto($socket, $deferred, $toggle);
7677
};
7778

7879
$this->loop->addReadStream($socket, $toggleCrypto);
7980
$toggleCrypto();
8081

81-
return $deferred->promise()->then(function () use ($stream, $toggle) {
82-
if ($toggle && $this->wrapSecure) {
83-
return new SecureStream($stream, $this->loop);
82+
$wrap = $this->wrapSecure && $toggle;
83+
$loop = $this->loop;
84+
85+
return $deferred->promise()->then(function () use ($stream, $wrap, $loop) {
86+
if ($wrap) {
87+
return new SecureStream($stream, $loop);
8488
}
8589

8690
$stream->resume();

0 commit comments

Comments
 (0)