Methods |
public
|
getStatusCode(): int
Gets the response status code.
Gets the response status code.
The status code is a 3-digit integer result code of the server's attempt
to understand and satisfy the request.
Deprecated
To be replaced by the PSR-7 version (compatible)
Returns
Implemented by
|
#
|
public
|
setStatusCode(int $code, string $reason = ''): $this
Return an instance with the specified status code and, optionally, reason phrase.
Return an instance with the specified status code and, optionally, reason phrase.
If no reason phrase is specified, will default recommended reason phrase for
the response's status code.
Parameters
$code |
The 3-digit integer result code to set.
|
$reason |
The reason phrase to use with the
provided status code; if none is provided, will
default to the IANA name.
|
Throws
Implemented by
|
#
|
public
|
getReason(): string
Gets the response phrase associated with the status code.
Gets the response phrase associated with the status code.
Deprecated
Implemented by
|
#
|
public
|
getReasonPhrase(): string
Gets the response reason phrase associated with the status code.
Gets the response reason phrase associated with the status code.
Because a reason phrase is not a required element in a response
status line, the reason phrase value MAY be null. Implementations MAY
choose to return the default RFC 7231 recommended reason phrase (or those
listed in the IANA HTTP Status Code Registry) for the response's
status code.
Returns
Reason phrase; must return an empty string if none present.
Implemented by
|
#
|
public
|
setDate(DateTime $date): $this
Sets the date header
|
#
|
public
|
setLastModified(DateTime|string $date): $this
Sets the Last-Modified date header.
Sets the Last-Modified date header.
$date can be either a string representation of the date or,
preferably, an instance of DateTime.
|
#
|
public
|
setLink(PagerInterface $pager): $this
Set the Link Header
|
#
|
public
|
setContentType(string $mime, string $charset = 'UTF-8'): $this
Sets the Content Type header for this response with the mime type
and, optionally, the charset.
Sets the Content Type header for this response with the mime type
and, optionally, the charset.
Implemented by
|
#
|
public
|
setJSON(array|string $body, bool $unencoded = false): $this
Converts the $body into JSON and sets the Content Type header.
Converts the $body into JSON and sets the Content Type header.
|
#
|
public
|
getJSON(): bool|string|null
Returns the current body, converted to JSON is it isn't already.
Returns the current body, converted to JSON is it isn't already.
Throws
|
#
|
public
|
setXML(array|string $body): $this
Converts $body into XML, and sets the correct Content-Type.
Converts $body into XML, and sets the correct Content-Type.
|
#
|
public
|
getXML(): bool|string|null
Retrieves the current body into XML and returns it.
Retrieves the current body into XML and returns it.
Throws
|
#
|
public
|
noCache(): $this
Sets the appropriate headers to ensure this response
is not cached by the browsers.
Sets the appropriate headers to ensure this response
is not cached by the browsers.
Implemented by
|
#
|
public
|
setCache(array $options = []): $this
A shortcut method that allows the developer to set all of the
cache-control headers in one method call.
A shortcut method that allows the developer to set all of the
cache-control headers in one method call.
The options array is used to provide the cache-control directives
for the header. It might look something like:
$options = [
'max-age' => 300,
's-maxage' => 900
'etag' => 'abcde',
];
Typical options are:
- etag
- last-modified
- max-age
- s-maxage
- private
- public
- must-revalidate
- proxy-revalidate
- no-transform
Implemented by
|
#
|
public
|
send(): $this
Sends the output to the browser.
Sends the output to the browser.
Implemented by
|
#
|
public
|
sendHeaders(): $this
Sends the headers of this HTTP request to the browser.
Sends the headers of this HTTP request to the browser.
|
#
|
public
|
sendBody(): $this
Sends the Body of the message to the browser.
Sends the Body of the message to the browser.
Implemented by
|
#
|
public
|
setCookie(
array|string $name,
string $value = '',
string $expire = '',
string $domain = '',
string $path = '/',
string $prefix = '',
bool $secure = false,
bool $httponly = false,
string|null $samesite = null,
): $this
Set a cookie
Set a cookie
Accepts an arbitrary number of binds (up to 7) or an associative
array in the first parameter containing all the values.
Parameters
$name |
Cookie name or array containing binds
|
$value |
Cookie value
|
$expire |
Cookie expiration time in seconds
|
$domain |
Cookie domain (e.g.: '.yourdomain.com')
|
$path |
Cookie path (default: '/')
|
$prefix |
Cookie name prefix
|
$secure |
Whether to only transfer cookies via SSL
|
$httponly |
Whether only make the cookie accessible via HTTP (no javascript)
|
|
#
|
public
|
hasCookie(string $name, ?string $value = null, string $prefix = ''): bool
Checks to see if the Response has a specified cookie or not.
Checks to see if the Response has a specified cookie or not.
|
#
|
public
|
getCookie(?string $name = null, string $prefix = ''): Cookie|Cookie[]|null
Returns the cookie
|
#
|
public
|
deleteCookie(string $name = '', string $domain = '', string $path = '/', string $prefix = ''): $this
Sets a cookie to be deleted when the response is sent.
Sets a cookie to be deleted when the response is sent.
|
#
|
public
|
getCookies(): Cookie[]
Returns all cookies currently set.
Returns all cookies currently set.
|
#
|
public
|
getCookieStore(): CookieStore
Returns the `CookieStore` instance.
Returns the CookieStore instance.
|
#
|
public
|
redirect(string $uri, string $method = 'auto', int $code = null): $this
Perform a redirect to a new URL, in two flavors: header or location.
Perform a redirect to a new URL, in two flavors: header or location.
Parameters
$uri |
The URI to redirect to
|
$code |
The type of redirection, defaults to 302
|
Throws
|
#
|
public
|
download(string $filename = '', string|null $data = '', bool $setMime = false): DownloadResponse|null
Force a download.
Force a download.
Generates the headers that force a download to happen. And
sends the file to the browser.
Parameters
$filename |
The path to the file to send
|
$data |
The data to be downloaded
|
$setMime |
Whether to try and send the actual MIME type
|
|
#
|
public
|
getCSP(): ContentSecurityPolicy
Get Content Security Policy handler.
Get Content Security Policy handler.
|
#
|
Constants |
public
|
HTTP_CONTINUE = 100
Constants for status codes.
From https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
|
#
|
public
|
HTTP_SWITCHING_PROTOCOLS = 101
|
#
|
public
|
HTTP_PROCESSING = 102
|
#
|
public
|
HTTP_EARLY_HINTS = 103
|
#
|
public
|
HTTP_OK = 200
|
#
|
public
|
HTTP_CREATED = 201
|
#
|
public
|
HTTP_ACCEPTED = 202
|
#
|
public
|
HTTP_NONAUTHORITATIVE_INFORMATION = 203
|
#
|
public
|
HTTP_NO_CONTENT = 204
|
#
|
public
|
HTTP_RESET_CONTENT = 205
|
#
|
public
|
HTTP_PARTIAL_CONTENT = 206
|
#
|
public
|
HTTP_MULTI_STATUS = 207
|
#
|
public
|
HTTP_ALREADY_REPORTED = 208
|
#
|
public
|
HTTP_IM_USED = 226
|
#
|
public
|
HTTP_MULTIPLE_CHOICES = 300
|
#
|
public
|
HTTP_MOVED_PERMANENTLY = 301
|
#
|
public
|
HTTP_FOUND = 302
|
#
|
public
|
HTTP_SEE_OTHER = 303
|
#
|
public
|
HTTP_NOT_MODIFIED = 304
|
#
|
public
|
HTTP_USE_PROXY = 305
|
#
|
public
|
HTTP_SWITCH_PROXY = 306
|
#
|
public
|
HTTP_TEMPORARY_REDIRECT = 307
|
#
|
public
|
HTTP_PERMANENT_REDIRECT = 308
|
#
|
public
|
HTTP_BAD_REQUEST = 400
|
#
|
public
|
HTTP_UNAUTHORIZED = 401
|
#
|
public
|
HTTP_PAYMENT_REQUIRED = 402
|
#
|
public
|
HTTP_FORBIDDEN = 403
|
#
|
public
|
HTTP_NOT_FOUND = 404
|
#
|
public
|
HTTP_METHOD_NOT_ALLOWED = 405
|
#
|
public
|
HTTP_NOT_ACCEPTABLE = 406
|
#
|
public
|
HTTP_PROXY_AUTHENTICATION_REQUIRED = 407
|
#
|
public
|
HTTP_REQUEST_TIMEOUT = 408
|
#
|
public
|
HTTP_CONFLICT = 409
|
#
|
public
|
HTTP_GONE = 410
|
#
|
public
|
HTTP_LENGTH_REQUIRED = 411
|
#
|
public
|
HTTP_PRECONDITION_FAILED = 412
|
#
|
public
|
HTTP_PAYLOAD_TOO_LARGE = 413
|
#
|
public
|
HTTP_URI_TOO_LONG = 414
|
#
|
public
|
HTTP_UNSUPPORTED_MEDIA_TYPE = 415
|
#
|
public
|
HTTP_RANGE_NOT_SATISFIABLE = 416
|
#
|
public
|
HTTP_EXPECTATION_FAILED = 417
|
#
|
public
|
HTTP_IM_A_TEAPOT = 418
|
#
|
public
|
HTTP_MISDIRECTED_REQUEST = 421
|
#
|
public
|
HTTP_UNPROCESSABLE_ENTITY = 422
|
#
|
public
|
HTTP_LOCKED = 423
|
#
|
public
|
HTTP_FAILED_DEPENDENCY = 424
|
#
|
public
|
HTTP_TOO_EARLY = 425
|
#
|
public
|
HTTP_UPGRADE_REQUIRED = 426
|
#
|
public
|
HTTP_PRECONDITION_REQUIRED = 428
|
#
|
public
|
HTTP_TOO_MANY_REQUESTS = 429
|
#
|
public
|
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431
|
#
|
public
|
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451
|
#
|
public
|
HTTP_CLIENT_CLOSED_REQUEST = 499
|
#
|
public
|
HTTP_INTERNAL_SERVER_ERROR = 500
|
#
|
public
|
HTTP_NOT_IMPLEMENTED = 501
|
#
|
public
|
HTTP_BAD_GATEWAY = 502
|
#
|
public
|
HTTP_SERVICE_UNAVAILABLE = 503
|
#
|
public
|
HTTP_GATEWAY_TIMEOUT = 504
|
#
|
public
|
HTTP_HTTP_VERSION_NOT_SUPPORTED = 505
|
#
|
public
|
HTTP_VARIANT_ALSO_NEGOTIATES = 506
|
#
|
public
|
HTTP_INSUFFICIENT_STORAGE = 507
|
#
|
public
|
HTTP_LOOP_DETECTED = 508
|
#
|
public
|
HTTP_NOT_EXTENDED = 510
|
#
|
public
|
HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511
|
#
|
public
|
HTTP_NETWORK_CONNECT_TIMEOUT_ERROR = 599
|
#
|