diff --git a/.travis.yml b/.travis.yml index 94d55bc3..db37918b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: php php: + - 5.3 - 5.4 - 5.5 - 5.6 diff --git a/composer.json b/composer.json index cfc6f04a..3d431527 100644 --- a/composer.json +++ b/composer.json @@ -4,11 +4,11 @@ "keywords": ["http"], "license": "MIT", "require": { - "php": ">=5.4.0", - "guzzlehttp/psr7": "^1.0", + "php": ">=5.3.0", + "ringcentral/psr7": "^1.0", "react/socket": "^0.4", "react/stream": "^0.4", - "evenement/evenement": "^2.0" + "evenement/evenement": "^2.0 || ^1.0" }, "autoload": { "psr-4": { diff --git a/src/RequestHeaderParser.php b/src/RequestHeaderParser.php index af70ed1b..7c44ab02 100644 --- a/src/RequestHeaderParser.php +++ b/src/RequestHeaderParser.php @@ -4,7 +4,7 @@ use Evenement\EventEmitter; use Exception; -use GuzzleHttp\Psr7 as g7; +use RingCentral\Psr7 as g7; /** * @event headers @@ -37,7 +37,7 @@ public function feed($data) try { $this->parseAndEmitRequest(); } catch (Exception $exception) { - $this->emit('error', [$exception]); + $this->emit('error', array($exception)); } $this->removeAllListeners(); } @@ -55,7 +55,7 @@ public function parseRequest($data) $psrRequest = g7\parse_request($headers); - $parsedQuery = []; + $parsedQuery = array(); $queryString = $psrRequest->getUri()->getQuery(); if ($queryString) { parse_str($queryString, $parsedQuery); diff --git a/src/Response.php b/src/Response.php index 36e375fc..bab5fc0f 100644 --- a/src/Response.php +++ b/src/Response.php @@ -17,18 +17,18 @@ class Response extends EventEmitter implements WritableStreamInterface public function __construct(ConnectionInterface $conn) { $this->conn = $conn; - - $this->conn->on('end', function () { - $this->close(); + $that = $this; + $this->conn->on('end', function () use ($that) { + $that->close(); }); - $this->conn->on('error', function ($error) { - $this->emit('error', array($error, $this)); - $this->close(); + $this->conn->on('error', function ($error) use ($that) { + $that->emit('error', array($error, $that)); + $that->close(); }); - $this->conn->on('drain', function () { - $this->emit('drain'); + $this->conn->on('drain', function () use ($that) { + $that->emit('drain'); }); } diff --git a/src/Server.php b/src/Server.php index 49535060..2f5f641a 100644 --- a/src/Server.php +++ b/src/Server.php @@ -14,18 +14,19 @@ class Server extends EventEmitter implements ServerInterface public function __construct(SocketServerInterface $io) { $this->io = $io; + $that = $this; - $this->io->on('connection', function (ConnectionInterface $conn) { + $this->io->on('connection', function (ConnectionInterface $conn) use ($that) { // TODO: http 1.1 keep-alive // TODO: chunked transfer encoding (also for outgoing data) // TODO: multipart parsing $parser = new RequestHeaderParser(); - $parser->on('headers', function (Request $request, $bodyBuffer) use ($conn, $parser) { + $parser->on('headers', function (Request $request, $bodyBuffer) use ($conn, $parser, $that) { // attach remote ip to the request as metadata $request->remoteAddress = $conn->getRemoteAddress(); - $this->handleRequest($conn, $request, $bodyBuffer); + $that->handleRequest($conn, $request, $bodyBuffer); $conn->removeListener('data', array($parser, 'feed')); $conn->on('end', function () use ($request) { @@ -42,12 +43,12 @@ public function __construct(SocketServerInterface $io) }); }); - $listener = [$parser, 'feed']; + $listener = array($parser, 'feed'); $conn->on('data', $listener); - $parser->on('error', function() use ($conn, $listener) { + $parser->on('error', function() use ($conn, $listener, $that) { // TODO: return 400 response $conn->removeListener('data', $listener); - $this->emit('error', func_get_args()); + $that->emit('error', func_get_args()); }); }); } diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 5cef7cfc..e79347e9 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -121,7 +121,7 @@ public function testParserErrorEmitted() $data = "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\nX-DATA: "; $data .= str_repeat('A', 4097 - strlen($data)) . "\r\n\r\n"; - $this->connection->emit('data', [$data]); + $this->connection->emit('data', array($data)); $this->assertInstanceOf('OverflowException', $error); $this->connection->expects($this->never())->method('write');