Zend_Http_Response_Stream

Zend_Http_Response represents an HTTP 1.0 / 1.1 response message.

Defined (1)

The class is defined in the following location(s).

/inc/VideoUploader/includes/Zend/Http/Response/Stream.php  
  1. class Zend_Http_Response_Stream extends Zend_Http_Response 
  2. /** 
  3. * Response as stream 
  4. * @var resource 
  5. */ 
  6. protected $stream; 
  7.  
  8. /** 
  9. * The name of the file containing the stream 
  10. * Will be empty if stream is not file-based. 
  11. * @var string 
  12. */ 
  13. protected $stream_name; 
  14.  
  15. /** 
  16. * Should we clean up the stream file when this response is closed? 
  17. * @var boolean 
  18. */ 
  19. protected $_cleanup; 
  20.  
  21. /** 
  22. * Get the response as stream 
  23. * @return resourse 
  24. */ 
  25. public function getStream() 
  26. return $this->stream; 
  27.  
  28. /** 
  29. * Set the response stream 
  30. * @param resourse $stream 
  31. * @return Zend_Http_Response_Stream 
  32. */ 
  33. public function setStream($stream) 
  34. $this->stream = $stream; 
  35. return $this; 
  36.  
  37. /** 
  38. * Get the cleanup trigger 
  39. * @return boolean 
  40. */ 
  41. public function getCleanup() { 
  42. return $this->_cleanup; 
  43.  
  44. /** 
  45. * Set the cleanup trigger 
  46. * @param bool $cleanup Set cleanup trigger 
  47. */ 
  48. public function setCleanup($cleanup = true) { 
  49. $this->_cleanup = $cleanup; 
  50.  
  51. /** 
  52. * Get file name associated with the stream 
  53. * @return string 
  54. */ 
  55. public function getStreamName() { 
  56. return $this->stream_name; 
  57.  
  58. /** 
  59. * Set file name associated with the stream 
  60. * @param string $stream_name Name to set 
  61. * @return Zend_Http_Response_Stream 
  62. */ 
  63. public function setStreamName($stream_name) { 
  64. $this->stream_name = $stream_name; 
  65. return $this; 
  66.  
  67.  
  68. /** 
  69. * HTTP response constructor 
  70. * In most cases, you would use Zend_Http_Response::fromString to parse an HTTP 
  71. * response string and create a new Zend_Http_Response object. 
  72. * NOTE: The constructor no longer accepts nulls or empty values for the code and 
  73. * headers and will throw an exception if the passed values do not form a valid HTTP 
  74. * responses. 
  75. * If no message is passed, the message will be guessed according to the response code. 
  76. * @param int $code Response code (200, 404, ...) 
  77. * @param array $headers Headers array 
  78. * @param string $body Response body 
  79. * @param string $version HTTP version 
  80. * @param string $message Response code as text 
  81. * @throws Zend_Http_Exception 
  82. */ 
  83. public function __construct($code, $headers, $body = null, $version = '1.1', $message = null) 
  84.  
  85. if(is_resource($body)) { 
  86. $this->setStream($body); 
  87. $body = ''; 
  88. parent::__construct($code, $headers, $body, $version, $message); 
  89.  
  90. /** 
  91. * Create a new Zend_Http_Response_Stream object from a string 
  92. * @param string $response_str 
  93. * @param resource $stream 
  94. * @return Zend_Http_Response_Stream 
  95. */ 
  96. public static function fromStream($response_str, $stream) 
  97. $code = self::extractCode($response_str); 
  98. $headers = self::extractHeaders($response_str); 
  99. $version = self::extractVersion($response_str); 
  100. $message = self::extractMessage($response_str); 
  101.  
  102. return new self($code, $headers, $stream, $version, $message); 
  103.  
  104. /** 
  105. * Get the response body as string 
  106. * This method returns the body of the HTTP response (the content), as it 
  107. * should be in it's readable version - that is, after decoding it (if it 
  108. * was decoded), deflating it (if it was gzip compressed), etc. 
  109. * If you want to get the raw body (as transfered on wire) use 
  110. * $this->getRawBody() instead. 
  111. * @return string 
  112. */ 
  113. public function getBody() 
  114. if($this->stream != null) { 
  115. $this->readStream(); 
  116. return parent::getBody(); 
  117.  
  118. /** 
  119. * Get the raw response body (as transfered "on wire") as string 
  120. * If the body is encoded (with Transfer-Encoding, not content-encoding - 
  121. * IE "chunked" body), gzip compressed, etc. it will not be decoded. 
  122. * @return string 
  123. */ 
  124. public function getRawBody() 
  125. if($this->stream) { 
  126. $this->readStream(); 
  127. return $this->body; 
  128.  
  129. /** 
  130. * Read stream content and return it as string 
  131. * Function reads the remainder of the body from the stream and closes the stream. 
  132. * @return string 
  133. */ 
  134. protected function readStream() 
  135. if(!is_resource($this->stream)) { 
  136. return ''; 
  137.  
  138. if(isset($headers['content-length'])) { 
  139. $this->body = stream_get_contents($this->stream, $headers['content-length']); 
  140. } else { 
  141. $this->body = stream_get_contents($this->stream); 
  142. fclose($this->stream); 
  143. $this->stream = null; 
  144.  
  145. public function __destruct() 
  146. if(is_resource($this->stream)) { 
  147. fclose($this->stream); 
  148. $this->stream = null; 
  149. if($this->_cleanup) { 
  150. @unlink($this->stream_name); 
  151.