1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-05 10:49:37 +02:00

Move from React 0.4.0 to 0.3.4 for PHP 5.3 compatibility reasons

This commit is contained in:
Afterster 2014-04-13 08:58:34 +02:00
parent d3f01a3bc7
commit 7f82bea13e
50 changed files with 608 additions and 1937 deletions

View file

@ -22,6 +22,7 @@ class Request extends EventEmitter implements WritableStreamInterface
const STATE_HEAD_WRITTEN = 2;
const STATE_END = 3;
private $loop;
private $connector;
private $requestData;
@ -31,8 +32,9 @@ class Request extends EventEmitter implements WritableStreamInterface
private $response;
private $state = self::STATE_INIT;
public function __construct(ConnectorInterface $connector, RequestData $requestData)
public function __construct(LoopInterface $loop, ConnectorInterface $connector, RequestData $requestData)
{
$this->loop = $loop;
$this->connector = $connector;
$this->requestData = $requestData;
}
@ -50,6 +52,7 @@ class Request extends EventEmitter implements WritableStreamInterface
$this->state = self::STATE_WRITING_HEAD;
$that = $this;
$requestData = $this->requestData;
$streamRef = &$this->stream;
$stateRef = &$this->state;
@ -57,13 +60,13 @@ class Request extends EventEmitter implements WritableStreamInterface
$this
->connect()
->then(
function ($stream) use ($requestData, &$streamRef, &$stateRef) {
function ($stream) use ($that, $requestData, &$streamRef, &$stateRef) {
$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('drain', array($that, 'handleDrain'));
$stream->on('data', array($that, 'handleData'));
$stream->on('end', array($that, 'handleEnd'));
$stream->on('error', array($that, 'handleError'));
$requestData->setProtocolVersion('1.0');
$headers = (string) $requestData;
@ -72,7 +75,7 @@ class Request extends EventEmitter implements WritableStreamInterface
$stateRef = Request::STATE_HEAD_WRITTEN;
$this->emit('headers-written', array($this));
$that->emit('headers-written', array($that));
},
array($this, 'handleError')
);
@ -88,8 +91,8 @@ class Request extends EventEmitter implements WritableStreamInterface
return $this->stream->write($data);
}
$this->on('headers-written', function ($this) use ($data) {
$this->write($data);
$this->on('headers-written', function ($that) use ($data) {
$that->write($data);
});
if (self::STATE_WRITING_HEAD > $this->state) {
@ -132,12 +135,13 @@ class Request extends EventEmitter implements WritableStreamInterface
$this->stream->removeListener('error', array($this, 'handleError'));
$this->response = $response;
$that = $this;
$response->on('end', function () {
$this->close();
$response->on('end', function () use ($that) {
$that->close();
});
$response->on('error', function (\Exception $error) {
$this->closeError(new \RuntimeException(
$response->on('error', function (\Exception $error) use ($that) {
$that->closeError(new \RuntimeException(
"An error occured in the response",
0,
$error
@ -225,10 +229,12 @@ class Request extends EventEmitter implements WritableStreamInterface
public function getResponseFactory()
{
if (null === $factory = $this->responseFactory) {
$loop = $this->loop;
$stream = $this->stream;
$factory = function ($protocol, $version, $code, $reasonPhrase, $headers) use ($stream) {
$factory = function ($protocol, $version, $code, $reasonPhrase, $headers) use ($loop, $stream) {
return new Response(
$loop,
$stream,
$protocol,
$version,