Zend Framework  3.0
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Response Class Reference

HTTP Response. More...

Public Member Functions

 getCookie ()
 
 setStatusCode ($code)
 Set HTTP status code and (optionally) message.
 
 getStatusCode ()
 Retrieve HTTP status code.
 
 setCustomStatusCode ($code)
 Set custom HTTP status code.
 
 setReasonPhrase ($reasonPhrase)
 
 getReasonPhrase ()
 Get HTTP status message.
 
 getBody ()
 Get the body of the response.
 
 isClientError ()
 Does the status code indicate a client error?
 
 isForbidden ()
 Is the request forbidden due to ACLs?
 
 isInformational ()
 Is the current status "informational"?
 
 isNotFound ()
 Does the status code indicate the resource is not found?
 
 isOk ()
 Do we have a normal, OK response?
 
 isServerError ()
 Does the status code reflect a server error?
 
 isRedirect ()
 Do we have a redirect?
 
 isSuccess ()
 Was the response successful?
 
 renderStatusLine ()
 Render the status line header.
 
 toString ()
 Render entire response as HTTP response string.
 
- Public Member Functions inherited from AbstractMessage
 setVersion ($version)
 Set the HTTP version for this object, one of 1.0 or 1.1 (AbstractMessage::VERSION_10, AbstractMessage::VERSION_11)
 
 getVersion ()
 Return the HTTP version for this request.
 
 setHeaders (Headers $headers)
 Provide an alternate Parameter Container implementation for headers in this object, (this is NOT the primary API for value setting, for that see getHeaders())
 
 getHeaders ()
 Return the header container responsible for headers.
 
 __toString ()
 Allow PHP casting of this object.
 
- Public Member Functions inherited from Message
 setMetadata ($spec, $value=null)
 Set message metadata.
 
 getMetadata ($key=null, $default=null)
 Retrieve all metadata or a single metadatum as specified by key.
 
 setContent ($value)
 Set message content.
 
 getContent ()
 Get message content.
 
 toString ()
 
- Public Member Functions inherited from MessageInterface
 getMetadata ($key=null)
 Get metadata.
 

Static Public Member Functions

static fromString ($string)
 Populate object from string.
 

Public Attributes

const STATUS_CODE_CUSTOM = 0
 #@+ int Status codes
 
const STATUS_CODE_100 = 100
 
const STATUS_CODE_101 = 101
 
const STATUS_CODE_102 = 102
 
const STATUS_CODE_200 = 200
 
const STATUS_CODE_201 = 201
 
const STATUS_CODE_202 = 202
 
const STATUS_CODE_203 = 203
 
const STATUS_CODE_204 = 204
 
const STATUS_CODE_205 = 205
 
const STATUS_CODE_206 = 206
 
const STATUS_CODE_207 = 207
 
const STATUS_CODE_208 = 208
 
const STATUS_CODE_300 = 300
 
const STATUS_CODE_301 = 301
 
const STATUS_CODE_302 = 302
 
const STATUS_CODE_303 = 303
 
const STATUS_CODE_304 = 304
 
const STATUS_CODE_305 = 305
 
const STATUS_CODE_306 = 306
 
const STATUS_CODE_307 = 307
 
const STATUS_CODE_400 = 400
 
const STATUS_CODE_401 = 401
 
const STATUS_CODE_402 = 402
 
const STATUS_CODE_403 = 403
 
const STATUS_CODE_404 = 404
 
const STATUS_CODE_405 = 405
 
const STATUS_CODE_406 = 406
 
const STATUS_CODE_407 = 407
 
const STATUS_CODE_408 = 408
 
const STATUS_CODE_409 = 409
 
const STATUS_CODE_410 = 410
 
const STATUS_CODE_411 = 411
 
const STATUS_CODE_412 = 412
 
const STATUS_CODE_413 = 413
 
const STATUS_CODE_414 = 414
 
const STATUS_CODE_415 = 415
 
const STATUS_CODE_416 = 416
 
const STATUS_CODE_417 = 417
 
const STATUS_CODE_418 = 418
 
const STATUS_CODE_422 = 422
 
const STATUS_CODE_423 = 423
 
const STATUS_CODE_424 = 424
 
const STATUS_CODE_425 = 425
 
const STATUS_CODE_426 = 426
 
const STATUS_CODE_428 = 428
 
const STATUS_CODE_429 = 429
 
const STATUS_CODE_431 = 431
 
const STATUS_CODE_500 = 500
 
const STATUS_CODE_501 = 501
 
const STATUS_CODE_502 = 502
 
const STATUS_CODE_503 = 503
 
const STATUS_CODE_504 = 504
 
const STATUS_CODE_505 = 505
 
const STATUS_CODE_506 = 506
 
const STATUS_CODE_507 = 507
 
const STATUS_CODE_508 = 508
 
const STATUS_CODE_511 = 511
 
- Public Attributes inherited from AbstractMessage
const VERSION_10 = '1.0'
 #@+ string Version constant numbers
 
const VERSION_11 = '1.1'
 

Protected Member Functions

 saveStatusCode ($code)
 Assign status code.
 
 decodeChunkedBody ($body)
 Decode a "chunked" transfer-encoded body and return the decoded text.
 
 decodeGzip ($body)
 Decode a gzip encoded message (when Content-encoding = gzip)
 
 decodeDeflate ($body)
 Decode a zlib deflated message (when Content-encoding = deflate)
 

Protected Attributes

 $recommendedReasonPhrases
 
 $statusCode = 200
 
 $reasonPhrase = null
 
- Protected Attributes inherited from AbstractMessage
 $version = self::VERSION_11
 
 $headers = null
 
- Protected Attributes inherited from Message
 $metadata = []
 
 $content = ''
 

Detailed Description

HTTP Response.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6

Member Function Documentation

decodeChunkedBody (   $body)
protected

Decode a "chunked" transfer-encoded body and return the decoded text.

Parameters
string$body
Returns
string
Exceptions
Exception\RuntimeException
decodeDeflate (   $body)
protected

Decode a zlib deflated message (when Content-encoding = deflate)

Currently requires PHP with zlib support

Parameters
string$body
Returns
string
Exceptions
Exception\RuntimeException

Some servers (IIS ?) send a broken deflate response, without the RFC-required zlib header.

We try to detect the zlib header, and if it does not exist we teat the body is plain DEFLATE content.

This method was adapted from PEAR HTTP_Request2 by (c) Alexey Borzov

http://framework.zend.com/issues/browse/ZF-6040

decodeGzip (   $body)
protected

Decode a gzip encoded message (when Content-encoding = gzip)

Currently requires PHP with zlib support

Parameters
string$body
Returns
string
Exceptions
Exception\RuntimeException
static fromString (   $string)
static

Populate object from string.

Parameters
string$string
Returns
self
Exceptions
Exception\InvalidArgumentException
getBody ( )

Get the body of the response.

Returns
string
getCookie ( )
Returns
Header[]
getReasonPhrase ( )

Get HTTP status message.

Returns
string
getStatusCode ( )

Retrieve HTTP status code.

Returns
int
isClientError ( )

Does the status code indicate a client error?

Returns
bool
isForbidden ( )

Is the request forbidden due to ACLs?

Returns
bool
isInformational ( )

Is the current status "informational"?

Returns
bool
isNotFound ( )

Does the status code indicate the resource is not found?

Returns
bool
isOk ( )

Do we have a normal, OK response?

Returns
bool
isRedirect ( )

Do we have a redirect?

Returns
bool
isServerError ( )

Does the status code reflect a server error?

Returns
bool
isSuccess ( )

Was the response successful?

Returns
bool
renderStatusLine ( )

Render the status line header.

Returns
string
saveStatusCode (   $code)
protected

Assign status code.

Parameters
int$code
Returns
self
setCustomStatusCode (   $code)

Set custom HTTP status code.

Parameters
int$code
Exceptions
Exception\InvalidArgumentException
Returns
self
setReasonPhrase (   $reasonPhrase)
Parameters
string$reasonPhrase
Returns
self
setStatusCode (   $code)

Set HTTP status code and (optionally) message.

Parameters
int$code
Exceptions
Exception\InvalidArgumentException
Returns
self
toString ( )

Render entire response as HTTP response string.

Returns
string

Member Data Documentation

$reasonPhrase = null
protected
$recommendedReasonPhrases
protected
Initial value:
= [
100 => 'Continue'
$statusCode = 200
protected
const STATUS_CODE_100 = 100
const STATUS_CODE_101 = 101
const STATUS_CODE_102 = 102
const STATUS_CODE_200 = 200
const STATUS_CODE_201 = 201
const STATUS_CODE_202 = 202
const STATUS_CODE_203 = 203
const STATUS_CODE_204 = 204
const STATUS_CODE_205 = 205
const STATUS_CODE_206 = 206
const STATUS_CODE_207 = 207
const STATUS_CODE_208 = 208
const STATUS_CODE_300 = 300
const STATUS_CODE_301 = 301
const STATUS_CODE_302 = 302
const STATUS_CODE_303 = 303
const STATUS_CODE_304 = 304
const STATUS_CODE_305 = 305
const STATUS_CODE_306 = 306
const STATUS_CODE_307 = 307
const STATUS_CODE_400 = 400
const STATUS_CODE_401 = 401
const STATUS_CODE_402 = 402
const STATUS_CODE_403 = 403
const STATUS_CODE_404 = 404
const STATUS_CODE_405 = 405
const STATUS_CODE_406 = 406
const STATUS_CODE_407 = 407
const STATUS_CODE_408 = 408
const STATUS_CODE_409 = 409
const STATUS_CODE_410 = 410
const STATUS_CODE_411 = 411
const STATUS_CODE_412 = 412
const STATUS_CODE_413 = 413
const STATUS_CODE_414 = 414
const STATUS_CODE_415 = 415
const STATUS_CODE_416 = 416
const STATUS_CODE_417 = 417
const STATUS_CODE_418 = 418
const STATUS_CODE_422 = 422
const STATUS_CODE_423 = 423
const STATUS_CODE_424 = 424
const STATUS_CODE_425 = 425
const STATUS_CODE_426 = 426
const STATUS_CODE_428 = 428
const STATUS_CODE_429 = 429
const STATUS_CODE_431 = 431
const STATUS_CODE_500 = 500
const STATUS_CODE_501 = 501
const STATUS_CODE_502 = 502
const STATUS_CODE_503 = 503
const STATUS_CODE_504 = 504
const STATUS_CODE_505 = 505
const STATUS_CODE_506 = 506
const STATUS_CODE_507 = 507
const STATUS_CODE_508 = 508
const STATUS_CODE_511 = 511
const STATUS_CODE_CUSTOM = 0

#@+ int Status codes