mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-05 02:39:47 +02:00
Move from React 0.4.0 to 0.3.4 for PHP 5.3 compatibility reasons
This commit is contained in:
parent
d3f01a3bc7
commit
7f82bea13e
50 changed files with 608 additions and 1937 deletions
|
@ -8,11 +8,13 @@ use React\SocketClient\ConnectorInterface;
|
|||
|
||||
class Client
|
||||
{
|
||||
private $loop;
|
||||
private $connectionManager;
|
||||
private $secureConnectionManager;
|
||||
|
||||
public function __construct(ConnectorInterface $connector, ConnectorInterface $secureConnector)
|
||||
public function __construct(LoopInterface $loop, ConnectorInterface $connector, ConnectorInterface $secureConnector)
|
||||
{
|
||||
$this->loop = $loop;
|
||||
$this->connector = $connector;
|
||||
$this->secureConnector = $secureConnector;
|
||||
}
|
||||
|
@ -21,7 +23,7 @@ class Client
|
|||
{
|
||||
$requestData = new RequestData($method, $url, $headers);
|
||||
$connectionManager = $this->getConnectorForScheme($requestData->getScheme());
|
||||
return new Request($connectionManager, $requestData);
|
||||
return new Request($this->loop, $connectionManager, $requestData);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class Factory
|
|||
{
|
||||
$connector = new Connector($loop, $resolver);
|
||||
$secureConnector = new SecureConnector($connector, $loop);
|
||||
return new Client($connector, $secureConnector);
|
||||
return new Client($loop, $connector, $secureConnector);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -11,16 +11,19 @@ use React\Stream\WritableStreamInterface;
|
|||
|
||||
class Response extends EventEmitter implements ReadableStreamInterface
|
||||
{
|
||||
private $loop;
|
||||
private $stream;
|
||||
private $protocol;
|
||||
private $version;
|
||||
private $code;
|
||||
private $reasonPhrase;
|
||||
private $headers;
|
||||
private $body;
|
||||
private $readable = true;
|
||||
|
||||
public function __construct(Stream $stream, $protocol, $version, $code, $reasonPhrase, $headers)
|
||||
public function __construct(LoopInterface $loop, Stream $stream, $protocol, $version, $code, $reasonPhrase, $headers)
|
||||
{
|
||||
$this->loop = $loop;
|
||||
$this->stream = $stream;
|
||||
$this->protocol = $protocol;
|
||||
$this->version = $version;
|
||||
|
@ -32,31 +35,36 @@ class Response extends EventEmitter implements ReadableStreamInterface
|
|||
$stream->on('error', array($this, 'handleError'));
|
||||
$stream->on('end', array($this, 'handleEnd'));
|
||||
}
|
||||
|
||||
|
||||
public function getProtocol()
|
||||
{
|
||||
return $this->protocol;
|
||||
}
|
||||
|
||||
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
|
||||
public function getReasonPhrase()
|
||||
{
|
||||
return $this->reasonPhrase;
|
||||
}
|
||||
|
||||
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function handleData($data)
|
||||
{
|
||||
|
|
|
@ -4,17 +4,18 @@
|
|||
"keywords": ["http"],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"guzzle/parser": "~3.0",
|
||||
"react/socket-client": "0.4.*",
|
||||
"react/dns": "0.4.*"
|
||||
"php": ">=5.3.3",
|
||||
"guzzle/parser": "2.8.*",
|
||||
"react/socket-client": "0.3.*",
|
||||
"react/dns": "0.3.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "React\\HttpClient\\": "" }
|
||||
"psr-0": { "React\\HttpClient": "" }
|
||||
},
|
||||
"target-dir": "React/HttpClient",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "0.4-dev"
|
||||
"dev-master": "0.3-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue