Skip to content

Commit e2fd12f

Browse files
authored
Merge pull request #127 from clue-labs/trolol
[RFC] Improve compatibility with legacy versions
2 parents c661c55 + 1ebab24 commit e2fd12f

12 files changed

+130
-130
lines changed

.travis.yml

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

33
php:
4+
# - 5.3 # requires old distro
45
- 5.4
56
- 5.5
67
- 5.6
@@ -14,6 +15,9 @@ php:
1415
dist: trusty
1516

1617
matrix:
18+
include:
19+
- php: 5.3
20+
dist: precise
1721
allow_failures:
1822
- php: nightly
1923
- php: hhvm

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ $ composer require react/http-client:^0.5.7
170170
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
171171

172172
This project aims to run on any platform and thus does not require any PHP
173-
extensions and supports running on legacy PHP 5.4 through current PHP 7+ and
173+
extensions and supports running on legacy PHP 5.3 through current PHP 7+ and
174174
HHVM.
175175
It's *highly recommended to use PHP 7+* for this project.
176176

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"keywords": ["http"],
55
"license": "MIT",
66
"require": {
7-
"php": ">=5.4.0",
8-
"evenement/evenement": "^3.0 || ^2.0",
7+
"php": ">=5.3.0",
8+
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
99
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
1010
"react/promise": "^2.1 || ^1.2.1",
1111
"react/socket": "^1.0 || ^0.8.4",

src/ChunkedStreamDecoder.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace React\HttpClient;
44

5-
use Evenement\EventEmitterTrait;
5+
use Evenement\EventEmitter;
66
use Exception;
77
use React\Stream\ReadableStreamInterface;
88
use React\Stream\Util;
@@ -11,12 +11,10 @@
1111
/**
1212
* @internal
1313
*/
14-
class ChunkedStreamDecoder implements ReadableStreamInterface
14+
class ChunkedStreamDecoder extends EventEmitter implements ReadableStreamInterface
1515
{
1616
const CRLF = "\r\n";
1717

18-
use EventEmitterTrait;
19-
2018
/**
2119
* @var string
2220
*/
@@ -55,9 +53,9 @@ public function __construct(ReadableStreamInterface $stream)
5553
$this->stream = $stream;
5654
$this->stream->on('data', array($this, 'handleData'));
5755
$this->stream->on('end', array($this, 'handleEnd'));
58-
Util::forwardEvents($this->stream, $this, [
56+
Util::forwardEvents($this->stream, $this, array(
5957
'error',
60-
]);
58+
));
6159
}
6260

6361
/** @internal */
@@ -89,9 +87,9 @@ protected function iterateBuffer()
8987
if ($this->nextChunkIsLength) {
9088
$crlfPosition = strpos($this->buffer, static::CRLF);
9189
if ($crlfPosition === false && strlen($this->buffer) > 1024) {
92-
$this->emit('error', [
90+
$this->emit('error', array(
9391
new Exception('Chunk length header longer then 1024 bytes'),
94-
]);
92+
));
9593
$this->close();
9694
return false;
9795
}
@@ -114,9 +112,9 @@ protected function iterateBuffer()
114112
}
115113
$this->nextChunkIsLength = false;
116114
if (dechex(hexdec($lengthChunk)) !== strtolower($lengthChunk)) {
117-
$this->emit('error', [
115+
$this->emit('error', array(
118116
new Exception('Unable to validate "' . $lengthChunk . '" as chunk length header'),
119-
]);
117+
));
120118
$this->close();
121119
return false;
122120
}
@@ -200,9 +198,9 @@ public function handleEnd()
200198

201199
$this->emit(
202200
'error',
203-
[
201+
array(
204202
new Exception('Stream ended with incomplete control code')
205-
]
203+
)
206204
);
207205
$this->close();
208206
}

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(LoopInterface $loop, ConnectorInterface $connector =
1919
$this->connector = $connector;
2020
}
2121

22-
public function request($method, $url, array $headers = [], $protocolVersion = '1.0')
22+
public function request($method, $url, array $headers = array(), $protocolVersion = '1.0')
2323
{
2424
$requestData = new RequestData($method, $url, $headers, $protocolVersion);
2525

src/Request.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace React\HttpClient;
44

5-
use Evenement\EventEmitterTrait;
5+
use Evenement\EventEmitter;
66
use React\Promise;
77
use React\Socket\ConnectionInterface;
88
use React\Socket\ConnectorInterface;
@@ -15,10 +15,8 @@
1515
* @event error
1616
* @event end
1717
*/
18-
class Request implements WritableStreamInterface
18+
class Request extends EventEmitter implements WritableStreamInterface
1919
{
20-
use EventEmitterTrait;
21-
2220
const STATE_INIT = 0;
2321
const STATE_WRITING_HEAD = 1;
2422
const STATE_HEAD_WRITTEN = 2;
@@ -54,17 +52,18 @@ private function writeHead()
5452
$streamRef = &$this->stream;
5553
$stateRef = &$this->state;
5654
$pendingWrites = &$this->pendingWrites;
55+
$that = $this;
5756

5857
$promise = $this->connect();
5958
$promise->then(
60-
function (ConnectionInterface $stream) use ($requestData, &$streamRef, &$stateRef, &$pendingWrites) {
59+
function (ConnectionInterface $stream) use ($requestData, &$streamRef, &$stateRef, &$pendingWrites, $that) {
6160
$streamRef = $stream;
6261

63-
$stream->on('drain', array($this, 'handleDrain'));
64-
$stream->on('data', array($this, 'handleData'));
65-
$stream->on('end', array($this, 'handleEnd'));
66-
$stream->on('error', array($this, 'handleError'));
67-
$stream->on('close', array($this, 'handleClose'));
62+
$stream->on('drain', array($that, 'handleDrain'));
63+
$stream->on('data', array($that, 'handleData'));
64+
$stream->on('end', array($that, 'handleEnd'));
65+
$stream->on('error', array($that, 'handleError'));
66+
$stream->on('close', array($that, 'handleClose'));
6867

6968
$headers = (string) $requestData;
7069

@@ -77,7 +76,7 @@ function (ConnectionInterface $stream) use ($requestData, &$streamRef, &$stateRe
7776
$pendingWrites = '';
7877

7978
if ($more) {
80-
$this->emit('drain');
79+
$that->emit('drain');
8180
}
8281
}
8382
},
@@ -154,11 +153,10 @@ public function handleData($data)
154153
return;
155154
}
156155

157-
$response->on('close', function () {
158-
$this->close();
159-
});
160-
$response->on('error', function (\Exception $error) {
161-
$this->closeError(new \RuntimeException(
156+
$response->on('close', array($this, 'close'));
157+
$that = $this;
158+
$response->on('error', function (\Exception $error) use ($that) {
159+
$that->closeError(new \RuntimeException(
162160
"An error occured in the response",
163161
0,
164162
$error

src/RequestData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class RequestData
99
private $headers;
1010
private $protocolVersion;
1111

12-
public function __construct($method, $url, array $headers = [], $protocolVersion = '1.0')
12+
public function __construct($method, $url, array $headers = array(), $protocolVersion = '1.0')
1313
{
1414
$this->method = $method;
1515
$this->url = $url;

src/Response.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
* @event error
1313
* @event end
1414
*/
15-
class Response extends EventEmitter implements ReadableStreamInterface
15+
class Response extends EventEmitter implements ReadableStreamInterface
1616
{
17-
1817
private $stream;
1918
private $protocol;
2019
private $version;
@@ -166,7 +165,7 @@ public function resume()
166165
$this->stream->resume();
167166
}
168167

169-
public function pipe(WritableStreamInterface $dest, array $options = [])
168+
public function pipe(WritableStreamInterface $dest, array $options = array())
170169
{
171170
Util::pipe($this, $dest, $options);
172171

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy