Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Http/Response/Stream.php
Go to the documentation of this file.
00001 <?php
00002 
00034 class Zend_Http_Response_Stream extends Zend_Http_Response
00035 {
00041     protected $stream;
00042 
00050     protected $stream_name;
00051 
00057     protected $_cleanup;
00058 
00064     public function getStream()
00065     {
00066         return $this->stream;
00067     }
00068 
00075     public function setStream($stream)
00076     {
00077         $this->stream = $stream;
00078         return $this;
00079     }
00080 
00086     public function getCleanup() {
00087         return $this->_cleanup;
00088     }
00089 
00095     public function setCleanup($cleanup = true) {
00096         $this->_cleanup = $cleanup;
00097     }
00098 
00104     public function getStreamName() {
00105         return $this->stream_name;
00106     }
00107 
00114     public function setStreamName($stream_name) {
00115         $this->stream_name = $stream_name;
00116         return $this;
00117     }
00118 
00119 
00139     public function __construct($code, $headers, $body = null, $version = '1.1', $message = null)
00140     {
00141 
00142         if(is_resource($body)) {
00143             $this->setStream($body);
00144             $body = '';
00145         }
00146         parent::__construct($code, $headers, $body, $version, $message);
00147     }
00148 
00156     public static function fromStream($response_str, $stream)
00157     {
00158         $code    = self::extractCode($response_str);
00159         $headers = self::extractHeaders($response_str);
00160         $version = self::extractVersion($response_str);
00161         $message = self::extractMessage($response_str);
00162 
00163         return new self($code, $headers, $stream, $version, $message);
00164     }
00165 
00178     public function getBody()
00179     {
00180         if($this->stream != null) {
00181             $this->readStream();
00182         }
00183         return parent::getBody();
00184     }
00185 
00194     public function getRawBody()
00195     {
00196         if($this->stream) {
00197             $this->readStream();
00198         }
00199         return $this->body;
00200     }
00201 
00209     protected function readStream()
00210     {
00211         if(!is_resource($this->stream)) {
00212             return '';
00213         }
00214 
00215         if(isset($headers['content-length'])) {
00216             $this->body = stream_get_contents($this->stream, $headers['content-length']);
00217         } else {
00218             $this->body = stream_get_contents($this->stream);
00219         }
00220         fclose($this->stream);
00221         $this->stream = null;
00222     }
00223 
00224     public function __destruct()
00225     {
00226         if(is_resource($this->stream)) {
00227             fclose($this->stream);
00228             $this->stream = null;
00229         }
00230         if($this->_cleanup) {
00231             @unlink($this->stream_name);
00232         }
00233     }
00234 
00235 }
 All Data Structures Namespaces Files Functions Variables Enumerations