Skip to content

Commit

Permalink
Compatibility with legacy PHP 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Feb 8, 2018
1 parent c661c55 commit 1ebab24
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 130 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php

php:
# - 5.3 # requires old distro
- 5.4
- 5.5
- 5.6
Expand All @@ -14,6 +15,9 @@ php:
dist: trusty

matrix:
include:
- php: 5.3
dist: precise
allow_failures:
- php: nightly
- php: hhvm
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ $ composer require react/http-client:^0.5.7
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

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

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"keywords": ["http"],
"license": "MIT",
"require": {
"php": ">=5.4.0",
"evenement/evenement": "^3.0 || ^2.0",
"php": ">=5.3.0",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
"react/promise": "^2.1 || ^1.2.1",
"react/socket": "^1.0 || ^0.8.4",
Expand Down
22 changes: 10 additions & 12 deletions src/ChunkedStreamDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace React\HttpClient;

use Evenement\EventEmitterTrait;
use Evenement\EventEmitter;
use Exception;
use React\Stream\ReadableStreamInterface;
use React\Stream\Util;
Expand All @@ -11,12 +11,10 @@
/**
* @internal
*/
class ChunkedStreamDecoder implements ReadableStreamInterface
class ChunkedStreamDecoder extends EventEmitter implements ReadableStreamInterface
{
const CRLF = "\r\n";

use EventEmitterTrait;

/**
* @var string
*/
Expand Down Expand Up @@ -55,9 +53,9 @@ public function __construct(ReadableStreamInterface $stream)
$this->stream = $stream;
$this->stream->on('data', array($this, 'handleData'));
$this->stream->on('end', array($this, 'handleEnd'));
Util::forwardEvents($this->stream, $this, [
Util::forwardEvents($this->stream, $this, array(
'error',
]);
));
}

/** @internal */
Expand Down Expand Up @@ -89,9 +87,9 @@ protected function iterateBuffer()
if ($this->nextChunkIsLength) {
$crlfPosition = strpos($this->buffer, static::CRLF);
if ($crlfPosition === false && strlen($this->buffer) > 1024) {
$this->emit('error', [
$this->emit('error', array(
new Exception('Chunk length header longer then 1024 bytes'),
]);
));
$this->close();
return false;
}
Expand All @@ -114,9 +112,9 @@ protected function iterateBuffer()
}
$this->nextChunkIsLength = false;
if (dechex(hexdec($lengthChunk)) !== strtolower($lengthChunk)) {
$this->emit('error', [
$this->emit('error', array(
new Exception('Unable to validate "' . $lengthChunk . '" as chunk length header'),
]);
));
$this->close();
return false;
}
Expand Down Expand Up @@ -200,9 +198,9 @@ public function handleEnd()

$this->emit(
'error',
[
array(
new Exception('Stream ended with incomplete control code')
]
)
);
$this->close();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(LoopInterface $loop, ConnectorInterface $connector =
$this->connector = $connector;
}

public function request($method, $url, array $headers = [], $protocolVersion = '1.0')
public function request($method, $url, array $headers = array(), $protocolVersion = '1.0')
{
$requestData = new RequestData($method, $url, $headers, $protocolVersion);

Expand Down
30 changes: 14 additions & 16 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace React\HttpClient;

use Evenement\EventEmitterTrait;
use Evenement\EventEmitter;
use React\Promise;
use React\Socket\ConnectionInterface;
use React\Socket\ConnectorInterface;
Expand All @@ -15,10 +15,8 @@
* @event error
* @event end
*/
class Request implements WritableStreamInterface
class Request extends EventEmitter implements WritableStreamInterface
{
use EventEmitterTrait;

const STATE_INIT = 0;
const STATE_WRITING_HEAD = 1;
const STATE_HEAD_WRITTEN = 2;
Expand Down Expand Up @@ -54,17 +52,18 @@ private function writeHead()
$streamRef = &$this->stream;
$stateRef = &$this->state;
$pendingWrites = &$this->pendingWrites;
$that = $this;

$promise = $this->connect();
$promise->then(
function (ConnectionInterface $stream) use ($requestData, &$streamRef, &$stateRef, &$pendingWrites) {
function (ConnectionInterface $stream) use ($requestData, &$streamRef, &$stateRef, &$pendingWrites, $that) {
$streamRef = $stream;

$stream->on('drain', array($this, 'handleDrain'));
$stream->on('data', array($this, 'handleData'));
$stream->on('end', array($this, 'handleEnd'));
$stream->on('error', array($this, 'handleError'));
$stream->on('close', array($this, 'handleClose'));
$stream->on('drain', array($that, 'handleDrain'));
$stream->on('data', array($that, 'handleData'));
$stream->on('end', array($that, 'handleEnd'));
$stream->on('error', array($that, 'handleError'));
$stream->on('close', array($that, 'handleClose'));

$headers = (string) $requestData;

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

if ($more) {
$this->emit('drain');
$that->emit('drain');
}
}
},
Expand Down Expand Up @@ -154,11 +153,10 @@ public function handleData($data)
return;
}

$response->on('close', function () {
$this->close();
});
$response->on('error', function (\Exception $error) {
$this->closeError(new \RuntimeException(
$response->on('close', array($this, 'close'));
$that = $this;
$response->on('error', function (\Exception $error) use ($that) {
$that->closeError(new \RuntimeException(
"An error occured in the response",
0,
$error
Expand Down
2 changes: 1 addition & 1 deletion src/RequestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RequestData
private $headers;
private $protocolVersion;

public function __construct($method, $url, array $headers = [], $protocolVersion = '1.0')
public function __construct($method, $url, array $headers = array(), $protocolVersion = '1.0')
{
$this->method = $method;
$this->url = $url;
Expand Down
5 changes: 2 additions & 3 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
* @event error
* @event end
*/
class Response extends EventEmitter implements ReadableStreamInterface
class Response extends EventEmitter implements ReadableStreamInterface
{

private $stream;
private $protocol;
private $version;
Expand Down Expand Up @@ -166,7 +165,7 @@ public function resume()
$this->stream->resume();
}

public function pipe(WritableStreamInterface $dest, array $options = [])
public function pipe(WritableStreamInterface $dest, array $options = array())
{
Util::pipe($this, $dest, $options);

Expand Down
Loading

0 comments on commit 1ebab24

Please sign in to comment.