Permalink
Browse files

add method to Zend\Http\Response\Stream

the content length is now exposed with getters and setters
fixed phpdoc
change atrribute $this->contentlength to getContentLength()
  • Loading branch information...
prolic committed Jan 20, 2013
1 parent 7da4fc6 commit f932275d8c7d9ef8f9aa5b22dcaa9349f02d8bcf
Showing with 8 additions and 7 deletions.
  1. +8 −7 library/Zend/Http/Response/Stream.php
@@ -72,7 +72,7 @@ public function setContentLength($contentLength = null)
/**
* Get content length
*
- * @return int
+ * @return int|null
*/
public function getContentLength()
{
@@ -202,12 +202,12 @@ public static function fromStream($responseString, $stream)
$headers = $response->getHeaders();
foreach ($headers as $header) {
if ($header instanceof \Zend\Http\Header\ContentLength) {
- $response->contentLength = (int) $header->getFieldValue();
- if (strlen($response->content) > $response->contentLength) {
+ $response->setContentLength((int) $header->getFieldValue());
+ if (strlen($response->content) > $response->getContentLength()) {
throw new Exception\OutOfRangeException(sprintf(
'Too much content was extracted from the stream (%d instead of %d bytes)',
strlen($response->content),
- $response->contentLength
+ $response->getContentLength()
));
}
break;
@@ -262,8 +262,9 @@ public function getRawBody()
*/
protected function readStream()
{
- if (!is_null($this->contentLength)) {
- $bytes = $this->contentLength - $this->contentStreamed;
+ $contentLength = $this->getContentLength();
+ if (!is_null($contentLength)) {
+ $bytes = $contentLength - $this->contentStreamed;
} else {
$bytes = -1; //Read the whole buffer
}
@@ -275,7 +276,7 @@ protected function readStream()
$this->content .= stream_get_contents($this->stream, $bytes);
$this->contentStreamed += strlen($this->content);
- if ($this->contentLength == $this->contentStreamed) {
+ if ($this->getContentLength() == $this->contentStreamed) {
$this->stream = null;
}
}

0 comments on commit f932275

Please sign in to comment.