Response
extends Response
in package
HTTP Response for current PHP environment
Table of Contents
Constants
- STATUS_CODE_100 = 100
- STATUS_CODE_101 = 101
- STATUS_CODE_102 = 102
- STATUS_CODE_200 = 200
- STATUS_CODE_201 = 201
- STATUS_CODE_202 = 202
- STATUS_CODE_203 = 203
- STATUS_CODE_204 = 204
- STATUS_CODE_205 = 205
- STATUS_CODE_206 = 206
- STATUS_CODE_207 = 207
- STATUS_CODE_208 = 208
- STATUS_CODE_226 = 226
- STATUS_CODE_300 = 300
- STATUS_CODE_301 = 301
- STATUS_CODE_302 = 302
- STATUS_CODE_303 = 303
- STATUS_CODE_304 = 304
- STATUS_CODE_305 = 305
- STATUS_CODE_306 = 306
- STATUS_CODE_307 = 307
- STATUS_CODE_308 = 308
- STATUS_CODE_400 = 400
- STATUS_CODE_401 = 401
- STATUS_CODE_402 = 402
- STATUS_CODE_403 = 403
- STATUS_CODE_404 = 404
- STATUS_CODE_405 = 405
- STATUS_CODE_406 = 406
- STATUS_CODE_407 = 407
- STATUS_CODE_408 = 408
- STATUS_CODE_409 = 409
- STATUS_CODE_410 = 410
- STATUS_CODE_411 = 411
- STATUS_CODE_412 = 412
- STATUS_CODE_413 = 413
- STATUS_CODE_414 = 414
- STATUS_CODE_415 = 415
- STATUS_CODE_416 = 416
- STATUS_CODE_417 = 417
- STATUS_CODE_418 = 418
- STATUS_CODE_422 = 422
- STATUS_CODE_423 = 423
- STATUS_CODE_424 = 424
- STATUS_CODE_425 = 425
- STATUS_CODE_426 = 426
- STATUS_CODE_428 = 428
- STATUS_CODE_429 = 429
- STATUS_CODE_431 = 431
- STATUS_CODE_444 = 444
- STATUS_CODE_451 = 451
- STATUS_CODE_499 = 499
- STATUS_CODE_500 = 500
- STATUS_CODE_501 = 501
- STATUS_CODE_502 = 502
- STATUS_CODE_503 = 503
- STATUS_CODE_504 = 504
- STATUS_CODE_505 = 505
- STATUS_CODE_506 = 506
- STATUS_CODE_507 = 507
- STATUS_CODE_508 = 508
- STATUS_CODE_510 = 510
- STATUS_CODE_511 = 511
- STATUS_CODE_599 = 599
- STATUS_CODE_CUSTOM = 0
- VERSION_10 = '1.0'
- VERSION_11 = '1.1'
- VERSION_2 = '2'
Properties
- $headersSent : bool
- $content : mixed
- $contentSent : bool
- $headers : Headers|null
- $metadata : array<string|int, mixed>
- $reasonPhrase : string|null
- $recommendedReasonPhrases : array<string|int, mixed>
- $statusCode : int
- $version : null|string
- The current used version (The value will be detected on getVersion)
- $headersSentHandler : null|callable
Methods
- __toString() : string
- Allow PHP casting of this object
- contentSent() : bool
- fromString() : static
- Populate object from string
- getBody() : string
- Get the body of the response
- getContent() : mixed
- Get message content
- getCookie() : array<string|int, SetCookie>
- getHeaders() : Headers
- Return the header container responsible for headers
- getMetadata() : mixed
- Retrieve all metadata or a single metadatum as specified by key
- getReasonPhrase() : string
- Get HTTP status message
- getStatusCode() : int
- Retrieve HTTP status code
- getVersion() : string
- Return the HTTP version for this response
- headersSent() : bool
- isClientError() : bool
- Does the status code indicate a client error?
- isForbidden() : bool
- Is the request forbidden due to ACLs?
- isGone() : bool
- Does the status code indicate the resource is gone?
- isInformational() : bool
- Is the current status "informational"?
- isNotFound() : bool
- Does the status code indicate the resource is not found?
- isOk() : bool
- Do we have a normal, OK response?
- isRedirect() : bool
- Do we have a redirect?
- isServerError() : bool
- Does the status code reflect a server error?
- isSuccess() : bool
- Was the response successful?
- renderStatusLine() : string
- Render the status line header
- send() : $this
- Send HTTP response
- sendContent() : $this
- Send content
- sendHeaders() : $this
- Send HTTP headers
- setContent() : Message
- Set message content
- setCustomStatusCode() : $this
- Set custom HTTP status code
- setHeaders() : $this
- Provide an alternate Parameter Container implementation for headers in this object, (this is NOT the primary API for value setting, for that see getHeaders())
- setHeadersSentHandler() : void
- setMetadata() : Message
- Set message metadata
- setReasonPhrase() : $this
- setStatusCode() : $this
- Set HTTP status code and (optionally) message
- setVersion() : $this
- Set the HTTP version for this object, one of 1.0, 1.1 or 2 (AbstractMessage::VERSION_10, AbstractMessage::VERSION_11, AbstractMessage::VERSION_2)
- toString() : string
- Render entire response as HTTP response string
- decodeChunkedBody() : string
- Decode a "chunked" transfer-encoded body and return the decoded text
- decodeDeflate() : string
- Decode a zlib deflated message (when Content-encoding = deflate)
- decodeGzip() : string
- Decode a gzip encoded message (when Content-encoding = gzip)
- detectVersion() : string
- Detect the current used protocol version.
- parseStatusLine() : mixed
- saveStatusCode() : $this
- Assign status code
Constants
STATUS_CODE_100
public
mixed
STATUS_CODE_100
= 100
STATUS_CODE_101
public
mixed
STATUS_CODE_101
= 101
STATUS_CODE_102
public
mixed
STATUS_CODE_102
= 102
STATUS_CODE_200
public
mixed
STATUS_CODE_200
= 200
STATUS_CODE_201
public
mixed
STATUS_CODE_201
= 201
STATUS_CODE_202
public
mixed
STATUS_CODE_202
= 202
STATUS_CODE_203
public
mixed
STATUS_CODE_203
= 203
STATUS_CODE_204
public
mixed
STATUS_CODE_204
= 204
STATUS_CODE_205
public
mixed
STATUS_CODE_205
= 205
STATUS_CODE_206
public
mixed
STATUS_CODE_206
= 206
STATUS_CODE_207
public
mixed
STATUS_CODE_207
= 207
STATUS_CODE_208
public
mixed
STATUS_CODE_208
= 208
STATUS_CODE_226
public
mixed
STATUS_CODE_226
= 226
STATUS_CODE_300
public
mixed
STATUS_CODE_300
= 300
STATUS_CODE_301
public
mixed
STATUS_CODE_301
= 301
STATUS_CODE_302
public
mixed
STATUS_CODE_302
= 302
STATUS_CODE_303
public
mixed
STATUS_CODE_303
= 303
STATUS_CODE_304
public
mixed
STATUS_CODE_304
= 304
STATUS_CODE_305
public
mixed
STATUS_CODE_305
= 305
STATUS_CODE_306
public
mixed
STATUS_CODE_306
= 306
STATUS_CODE_307
public
mixed
STATUS_CODE_307
= 307
STATUS_CODE_308
public
mixed
STATUS_CODE_308
= 308
STATUS_CODE_400
public
mixed
STATUS_CODE_400
= 400
STATUS_CODE_401
public
mixed
STATUS_CODE_401
= 401
STATUS_CODE_402
public
mixed
STATUS_CODE_402
= 402
STATUS_CODE_403
public
mixed
STATUS_CODE_403
= 403
STATUS_CODE_404
public
mixed
STATUS_CODE_404
= 404
STATUS_CODE_405
public
mixed
STATUS_CODE_405
= 405
STATUS_CODE_406
public
mixed
STATUS_CODE_406
= 406
STATUS_CODE_407
public
mixed
STATUS_CODE_407
= 407
STATUS_CODE_408
public
mixed
STATUS_CODE_408
= 408
STATUS_CODE_409
public
mixed
STATUS_CODE_409
= 409
STATUS_CODE_410
public
mixed
STATUS_CODE_410
= 410
STATUS_CODE_411
public
mixed
STATUS_CODE_411
= 411
STATUS_CODE_412
public
mixed
STATUS_CODE_412
= 412
STATUS_CODE_413
public
mixed
STATUS_CODE_413
= 413
STATUS_CODE_414
public
mixed
STATUS_CODE_414
= 414
STATUS_CODE_415
public
mixed
STATUS_CODE_415
= 415
STATUS_CODE_416
public
mixed
STATUS_CODE_416
= 416
STATUS_CODE_417
public
mixed
STATUS_CODE_417
= 417
STATUS_CODE_418
public
mixed
STATUS_CODE_418
= 418
STATUS_CODE_422
public
mixed
STATUS_CODE_422
= 422
STATUS_CODE_423
public
mixed
STATUS_CODE_423
= 423
STATUS_CODE_424
public
mixed
STATUS_CODE_424
= 424
STATUS_CODE_425
public
mixed
STATUS_CODE_425
= 425
STATUS_CODE_426
public
mixed
STATUS_CODE_426
= 426
STATUS_CODE_428
public
mixed
STATUS_CODE_428
= 428
STATUS_CODE_429
public
mixed
STATUS_CODE_429
= 429
STATUS_CODE_431
public
mixed
STATUS_CODE_431
= 431
STATUS_CODE_444
public
mixed
STATUS_CODE_444
= 444
STATUS_CODE_451
public
mixed
STATUS_CODE_451
= 451
STATUS_CODE_499
public
mixed
STATUS_CODE_499
= 499
STATUS_CODE_500
public
mixed
STATUS_CODE_500
= 500
STATUS_CODE_501
public
mixed
STATUS_CODE_501
= 501
STATUS_CODE_502
public
mixed
STATUS_CODE_502
= 502
STATUS_CODE_503
public
mixed
STATUS_CODE_503
= 503
STATUS_CODE_504
public
mixed
STATUS_CODE_504
= 504
STATUS_CODE_505
public
mixed
STATUS_CODE_505
= 505
STATUS_CODE_506
public
mixed
STATUS_CODE_506
= 506
STATUS_CODE_507
public
mixed
STATUS_CODE_507
= 507
STATUS_CODE_508
public
mixed
STATUS_CODE_508
= 508
STATUS_CODE_510
public
mixed
STATUS_CODE_510
= 510
STATUS_CODE_511
public
mixed
STATUS_CODE_511
= 511
STATUS_CODE_599
public
mixed
STATUS_CODE_599
= 599
STATUS_CODE_CUSTOM
public
mixed
STATUS_CODE_CUSTOM
= 0
VERSION_10
public
mixed
VERSION_10
= '1.0'
VERSION_11
public
mixed
VERSION_11
= '1.1'
VERSION_2
public
mixed
VERSION_2
= '2'
Properties
$headersSent
public
bool
$headersSent
Tags
$content
protected
mixed
$content
= ''
$contentSent
protected
bool
$contentSent
= false
$headers
protected
Headers|null
$headers
$metadata
protected
array<string|int, mixed>
$metadata
= []
$reasonPhrase
protected
string|null
$reasonPhrase
Null means it will be looked up from the $reasonPhrase list above
$recommendedReasonPhrases
protected
array<string|int, mixed>
$recommendedReasonPhrases
= [
// INFORMATIONAL CODES
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
// SUCCESS CODES
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-status',
208 => 'Already Reported',
226 => 'IM Used',
// REDIRECTION CODES
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
306 => 'Switch Proxy',
// Deprecated
307 => 'Temporary Redirect',
308 => 'Permanent Redirect',
// CLIENT ERROR
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Time-out',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Content Too Large',
414 => 'URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Range Not Satisfiable',
417 => 'Expectation Failed',
418 => 'I\'m a teapot',
422 => 'Unprocessable Content',
423 => 'Locked',
424 => 'Failed Dependency',
425 => 'Too Early',
426 => 'Upgrade Required',
428 => 'Precondition Required',
429 => 'Too Many Requests',
431 => 'Request Header Fields Too Large',
444 => 'Connection Closed Without Response',
451 => 'Unavailable For Legal Reasons',
499 => 'Client Closed Request',
// SERVER ERROR
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version not supported',
506 => 'Variant Also Negotiates',
507 => 'Insufficient Storage',
508 => 'Loop Detected',
510 => 'Not Extended',
511 => 'Network Authentication Required',
599 => 'Network Connect Timeout Error',
]
Recommended Reason Phrases
$statusCode
protected
int
$statusCode
= 200
Status code
$version
The current used version (The value will be detected on getVersion)
protected
null|string
$version
$headersSentHandler
private
null|callable
$headersSentHandler
Methods
__toString()
Allow PHP casting of this object
public
__toString() : string
Return values
stringcontentSent()
public
contentSent() : bool
Return values
boolfromString()
Populate object from string
public
static fromString(string $string) : static
Parameters
- $string : string
Tags
Return values
staticgetBody()
Get the body of the response
public
getBody() : string
Return values
stringgetContent()
Get message content
public
getContent() : mixed
getCookie()
public
getCookie() : array<string|int, SetCookie>
Return values
array<string|int, SetCookie>getHeaders()
Return the header container responsible for headers
public
getHeaders() : Headers
Return values
HeadersgetMetadata()
Retrieve all metadata or a single metadatum as specified by key
public
getMetadata([null|string|int $key = null ][, null|mixed $default = null ]) : mixed
Parameters
- $key : null|string|int = null
- $default : null|mixed = null
Tags
getReasonPhrase()
Get HTTP status message
public
getReasonPhrase() : string
Return values
stringgetStatusCode()
Retrieve HTTP status code
public
getStatusCode() : int
Return values
intgetVersion()
Return the HTTP version for this response
public
getVersion() : string
Tags
Return values
stringheadersSent()
public
headersSent() : bool
Return values
boolisClientError()
Does the status code indicate a client error?
public
isClientError() : bool
Return values
boolisForbidden()
Is the request forbidden due to ACLs?
public
isForbidden() : bool
Return values
boolisGone()
Does the status code indicate the resource is gone?
public
isGone() : bool
Return values
boolisInformational()
Is the current status "informational"?
public
isInformational() : bool
Return values
boolisNotFound()
Does the status code indicate the resource is not found?
public
isNotFound() : bool
Return values
boolisOk()
Do we have a normal, OK response?
public
isOk() : bool
Return values
boolisRedirect()
Do we have a redirect?
public
isRedirect() : bool
Return values
boolisServerError()
Does the status code reflect a server error?
public
isServerError() : bool
Return values
boolisSuccess()
Was the response successful?
public
isSuccess() : bool
Return values
boolrenderStatusLine()
Render the status line header
public
renderStatusLine() : string
Return values
stringsend()
Send HTTP response
public
send() : $this
Return values
$thissendContent()
Send content
public
sendContent() : $this
Return values
$thissendHeaders()
Send HTTP headers
public
sendHeaders() : $this
Return values
$thissetContent()
Set message content
public
setContent(mixed $value) : Message
Parameters
- $value : mixed
Return values
MessagesetCustomStatusCode()
Set custom HTTP status code
public
setCustomStatusCode(int $code) : $this
Parameters
- $code : int
Tags
Return values
$thissetHeaders()
Provide an alternate Parameter Container implementation for headers in this object, (this is NOT the primary API for value setting, for that see getHeaders())
public
setHeaders(Headers $headers) : $this
Parameters
- $headers : Headers
Tags
Return values
$thissetHeadersSentHandler()
public
setHeadersSentHandler(callable $handler) : void
Parameters
- $handler : callable
setMetadata()
Set message metadata
public
setMetadata(string|int|array<string|int, mixed>|Traversable $spec[, mixed $value = null ]) : Message
Non-destructive setting of message metadata; always adds to the metadata, never overwrites the entire metadata container.
Parameters
- $spec : string|int|array<string|int, mixed>|Traversable
- $value : mixed = null
Tags
Return values
MessagesetReasonPhrase()
public
setReasonPhrase(string $reasonPhrase) : $this
Parameters
- $reasonPhrase : string
Return values
$thissetStatusCode()
Set HTTP status code and (optionally) message
public
setStatusCode(int $code) : $this
Parameters
- $code : int
Tags
Return values
$thissetVersion()
Set the HTTP version for this object, one of 1.0, 1.1 or 2 (AbstractMessage::VERSION_10, AbstractMessage::VERSION_11, AbstractMessage::VERSION_2)
public
setVersion(string $version) : $this
Parameters
- $version : string
-
(Must be 1.0, 1.1 or 2)
Tags
Return values
$thistoString()
Render entire response as HTTP response string
public
toString() : string
Return values
stringdecodeChunkedBody()
Decode a "chunked" transfer-encoded body and return the decoded text
protected
decodeChunkedBody(string $body) : string
Parameters
- $body : string
Tags
Return values
stringdecodeDeflate()
Decode a zlib deflated message (when Content-encoding = deflate)
protected
decodeDeflate(string $body) : string
Currently requires PHP with zlib support
Parameters
- $body : string
Tags
Return values
stringdecodeGzip()
Decode a gzip encoded message (when Content-encoding = gzip)
protected
decodeGzip(string $body) : string
Currently requires PHP with zlib support
Parameters
- $body : string
Tags
Return values
stringdetectVersion()
Detect the current used protocol version.
protected
detectVersion() : string
If detection failed it falls back to version 1.0.
Return values
stringparseStatusLine()
protected
parseStatusLine(string $line) : mixed
Parameters
- $line : string
Tags
saveStatusCode()
Assign status code
protected
saveStatusCode(int $code) : $this
Parameters
- $code : int