Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Http_Response_Stream Class Reference
Inheritance diagram for Zend_Http_Response_Stream:
Zend_Http_Response

Public Member Functions

 getStream ()
 
 setStream ($stream)
 
 getCleanup ()
 
 setCleanup ($cleanup=true)
 
 getStreamName ()
 
 setStreamName ($stream_name)
 
 __construct ($code, $headers, $body=null, $version='1.1', $message=null)
 
 getBody ()
 
 getRawBody ()
 
 __destruct ()
 
- Public Member Functions inherited from Zend_Http_Response
 __construct ($code, array $headers, $body=null, $version='1.1', $message=null)
 
 isError ()
 
 isSuccessful ()
 
 isRedirect ()
 
 getBody ()
 
 getRawBody ()
 
 getVersion ()
 
 getStatus ()
 
 getMessage ()
 
 getHeaders ()
 
 getHeader ($header)
 
 getHeadersAsString ($status_line=true, $br="\n")
 
 asString ($br="\r\n")
 
 __toString ()
 

Static Public Member Functions

static fromStream ($response_str, $stream)
 
- Static Public Member Functions inherited from Zend_Http_Response
static responseCodeAsText ($code=null, $http11=true)
 
static extractCode ($response_str)
 
static extractMessage ($response_str)
 
static extractVersion ($response_str)
 
static extractHeaders ($response_str)
 
static extractBody ($response_str)
 
static decodeChunkedBody ($body)
 
static decodeGzip ($body)
 
static decodeDeflate ($body)
 
static fromString ($response_str)
 

Protected Member Functions

 readStream ()
 

Protected Attributes

 $stream
 
 $stream_name
 
 $_cleanup
 
- Protected Attributes inherited from Zend_Http_Response
 $version
 
 $code
 
 $message
 
 $headers = array()
 
 $body
 

Additional Inherited Members

- Static Protected Attributes inherited from Zend_Http_Response
static $messages
 

Detailed Description

Definition at line 34 of file Stream.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $code,
  $headers,
  $body = null,
  $version = '1.1',
  $message = null 
)

HTTP response constructor

In most cases, you would use Zend_Http_Response::fromString to parse an HTTP response string and create a new Zend_Http_Response object.

NOTE: The constructor no longer accepts nulls or empty values for the code and headers and will throw an exception if the passed values do not form a valid HTTP responses.

If no message is passed, the message will be guessed according to the response code.

Parameters
int$codeResponse code (200, 404, ...)
array$headersHeaders array
string$bodyResponse body
string$versionHTTP version
string$messageResponse code as text
Exceptions
Zend_Http_Exception

Definition at line 139 of file Stream.php.

140  {
141 
142  if(is_resource($body)) {
143  $this->setStream($body);
144  $body = '';
145  }
146  parent::__construct($code, $headers, $body, $version, $message);
147  }

◆ __destruct()

__destruct ( )

Definition at line 224 of file Stream.php.

225  {
226  if(is_resource($this->stream)) {
227  fclose($this->stream);
228  $this->stream = null;
229  }
230  if($this->_cleanup) {
231  @unlink($this->stream_name);
232  }
233  }

Member Function Documentation

◆ fromStream()

static fromStream (   $response_str,
  $stream 
)
static

Create a new Zend_Http_Response_Stream object from a string

Parameters
string$response_str
resource$stream
Returns
Zend_Http_Response_Stream

Definition at line 156 of file Stream.php.

157  {
158  $code = self::extractCode($response_str);
159  $headers = self::extractHeaders($response_str);
160  $version = self::extractVersion($response_str);
161  $message = self::extractMessage($response_str);
162 
163  return new self($code, $headers, $stream, $version, $message);
164  }
static extractHeaders($response_str)
Definition: Response.php:500
static extractVersion($response_str)
Definition: Response.php:483
static extractMessage($response_str)
Definition: Response.php:466
static extractCode($response_str)
Definition: Response.php:449

◆ getBody()

getBody ( )

Get the response body as string

This method returns the body of the HTTP response (the content), as it should be in it's readable version - that is, after decoding it (if it was decoded), deflating it (if it was gzip compressed), etc.

If you want to get the raw body (as transfered on wire) use $this->getRawBody() instead.

Returns
string

Definition at line 178 of file Stream.php.

179  {
180  if($this->stream != null) {
181  $this->readStream();
182  }
183  return parent::getBody();
184  }

◆ getCleanup()

getCleanup ( )

Get the cleanup trigger

Returns
boolean

Definition at line 86 of file Stream.php.

86  {
87  return $this->_cleanup;
88  }

◆ getRawBody()

getRawBody ( )

Get the raw response body (as transfered "on wire") as string

If the body is encoded (with Transfer-Encoding, not content-encoding - IE "chunked" body), gzip compressed, etc. it will not be decoded.

Returns
string

Definition at line 194 of file Stream.php.

195  {
196  if($this->stream) {
197  $this->readStream();
198  }
199  return $this->body;
200  }

◆ getStream()

getStream ( )

Get the response as stream

Returns
resourse

Definition at line 64 of file Stream.php.

65  {
66  return $this->stream;
67  }

◆ getStreamName()

getStreamName ( )

Get file name associated with the stream

Returns
string

Definition at line 104 of file Stream.php.

104  {
105  return $this->stream_name;
106  }

◆ readStream()

readStream ( )
protected

Read stream content and return it as string

Function reads the remainder of the body from the stream and closes the stream.

Returns
string

Definition at line 209 of file Stream.php.

210  {
211  if(!is_resource($this->stream)) {
212  return '';
213  }
214 
215  if(isset($headers['content-length'])) {
216  $this->body = stream_get_contents($this->stream, $headers['content-length']);
217  } else {
218  $this->body = stream_get_contents($this->stream);
219  }
220  fclose($this->stream);
221  $this->stream = null;
222  }

◆ setCleanup()

setCleanup (   $cleanup = true)

Set the cleanup trigger

Parameters
bool$cleanupSet cleanup trigger

Definition at line 95 of file Stream.php.

95  {
96  $this->_cleanup = $cleanup;
97  }

◆ setStream()

setStream (   $stream)

Set the response stream

Parameters
resourse$stream
Returns
Zend_Http_Response_Stream

Definition at line 75 of file Stream.php.

76  {
77  $this->stream = $stream;
78  return $this;
79  }

◆ setStreamName()

setStreamName (   $stream_name)

Set file name associated with the stream

Parameters
string$stream_nameName to set
Returns
Zend_Http_Response_Stream

Definition at line 114 of file Stream.php.

114  {
115  $this->stream_name = $stream_name;
116  return $this;
117  }

Field Documentation

◆ $_cleanup

$_cleanup
protected

Definition at line 57 of file Stream.php.

◆ $stream

$stream
protected

Definition at line 41 of file Stream.php.

◆ $stream_name

$stream_name
protected

Definition at line 50 of file Stream.php.


The documentation for this class was generated from the following file: