Skip to content

Commit

Permalink
Merge branch '0.4' into drop-get-body
Browse files Browse the repository at this point in the history
* 0.4:
  Move to 0.4.0 section in CHANGELOG
  Remove PHP 5.3 from travis builds
  Remove $that craziness from SecureConnector
  Add 5.4 to CHANGELOG
  Remove horribly annoying 5.3 StreamInterface extends bug
  Clean up annoying 5.3 $that = $this
  Require PHP 5.4.0 as a minimum

Conflicts:
	CHANGELOG.md
  • Loading branch information
igorw committed Apr 21, 2013
2 parents 0db9f8b + 80fcf21 commit 42ac73d
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,20 @@ public function writeHead()

$this->state = self::STATE_WRITING_HEAD;

$that = $this;
$requestData = $this->requestData;
$streamRef = &$this->stream;
$stateRef = &$this->state;

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

$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('drain', array($this, 'handleDrain'));
$stream->on('data', array($this, 'handleData'));
$stream->on('end', array($this, 'handleEnd'));
$stream->on('error', array($this, 'handleError'));

$requestData->setProtocolVersion('1.0');
$headers = (string) $requestData;
Expand All @@ -75,7 +74,7 @@ function ($stream) use ($that, $requestData, &$streamRef, &$stateRef) {

$stateRef = Request::STATE_HEAD_WRITTEN;

$that->emit('headers-written', array($that));
$this->emit('headers-written', array($this));
},
array($this, 'handleError')
);
Expand All @@ -91,8 +90,8 @@ public function write($data)
return $this->stream->write($data);
}

$this->on('headers-written', function ($that) use ($data) {
$that->write($data);
$this->on('headers-written', function ($this) use ($data) {
$this->write($data);
});

if (self::STATE_WRITING_HEAD > $this->state) {
Expand Down Expand Up @@ -135,13 +134,12 @@ public function handleData($data)
$this->stream->removeListener('error', array($this, 'handleError'));

$this->response = $response;
$that = $this;

$response->on('end', function () use ($that) {
$that->close();
$response->on('end', function () {
$this->close();
});
$response->on('error', function (\Exception $error) use ($that) {
$that->closeError(new \RuntimeException(
$response->on('error', function (\Exception $error) {
$this->closeError(new \RuntimeException(
"An error occured in the response",
0,
$error
Expand Down

0 comments on commit 42ac73d

Please sign in to comment.