added new socket manager, errorhandling and testing is not finished yet

This commit is contained in:
kremsy
2015-06-21 20:43:18 +02:00
parent eaf8819a57
commit fc5a3e04b6
32 changed files with 2627 additions and 0 deletions

View File

@ -0,0 +1,59 @@
<?php
namespace React\Stream;
use React\Promise\Deferred;
use React\Promise\PromisorInterface;
class BufferedSink extends WritableStream implements PromisorInterface
{
private $buffer = '';
private $deferred;
public function __construct()
{
$this->deferred = new Deferred();
$this->on('pipe', array($this, 'handlePipeEvent'));
$this->on('error', array($this, 'handleErrorEvent'));
}
public function handlePipeEvent($source)
{
Util::forwardEvents($source, $this, array('error'));
}
public function handleErrorEvent($e)
{
$this->deferred->reject($e);
}
public function write($data)
{
$this->buffer .= $data;
$this->deferred->progress($data);
}
public function close()
{
if ($this->closed) {
return;
}
parent::close();
$this->deferred->resolve($this->buffer);
}
public function promise()
{
return $this->deferred->promise();
}
public static function createPromise(ReadableStreamInterface $stream)
{
$sink = new static();
$stream->pipe($sink);
return $sink->promise();
}
}