Overview

Namespaces

  • api
  • config
  • database
  • PHP
  • Slim
    • Exception
    • Http
    • Middleware
  • utiliy

Classes

  • Headers
  • Request
  • Response
  • Util
  • Overview
  • Namespace
  • Class
  • Tree

Class Response

Response

This is a simple abstraction over top an HTTP response. This provides methods to set the HTTP status, the HTTP headers, and the HTTP body.

Slim\Http\Response implements ArrayAccess, Countable, IteratorAggregate
Namespace: Slim\Http
Package: Slim
Author: Josh Lockhart
Since: 1.0.0
Located at thirdparty/Slim/Http/Response.php
Methods summary
public
# __construct( string $body = '', integer $status = 200, Slim\Http\Headers|array $header = array() )

Constructor

Constructor

Parameters

$body
string
$body The HTTP response body
$status
integer
$status The HTTP response status
$header
Slim\Http\Headers|array
$header The HTTP response headers
public integer
# status( integer|null $status = null )

Get and set status

Get and set status

Parameters

$status
integer|null
$status

Returns

integer
public string
# header( string $name, string|null $value = null )

Get and set header

Get and set header

Parameters

$name
string
$name Header name
$value
string|null
$value Header value

Returns

string
Header value
public Slim\Http\Headers
# headers( )

Get headers

Get headers

Returns

Slim\Http\Headers
public string
# body( string|null $body = null )

Get and set body

Get and set body

Parameters

$body
string|null
$body Content of HTTP response body

Returns

string
public integer
# length( integer|null $length = null )

Get and set length

Get and set length

Parameters

$length
integer|null
$length

Returns

integer
public string
# write( string $body, boolean $replace = false )

Append HTTP response body

Append HTTP response body

Parameters

$body
string
$body Content to append to the current HTTP response body
$replace
boolean
$replace Overwrite existing response body?

Returns

string
The updated HTTP response body
public array[int
# finalize( )

Finalize

Finalize

This prepares this response and returns an array of [status, headers, body]. This array is passed to outer middleware if available or directly to the Slim run method.

Returns

array[int
status, array headers, string body]
public
# setCookie( string $name, string|array $value )

Set cookie

Set cookie

Instead of using PHP's setcookie() function, Slim manually constructs the HTTP Set-Cookie header on its own and delegates this responsibility to the Slim_Http_Util class. This response's header is passed by reference to the utility class and is directly modified. By not relying on PHP's native implementation, Slim allows middleware the opportunity to massage or analyze the raw header before the response is ultimately delivered to the HTTP client.

Parameters

$name
string
$name The name of the cookie
$value
string|array
$value If string, the value of cookie; if array, properties for cookie including: value, expire, path, domain, secure, httponly
public
# deleteCookie( string $name, array $value = array() )

Delete cookie

Delete cookie

Instead of using PHP's setcookie() function, Slim manually constructs the HTTP Set-Cookie header on its own and delegates this responsibility to the Slim_Http_Util class. This response's header is passed by reference to the utility class and is directly modified. By not relying on PHP's native implementation, Slim allows middleware the opportunity to massage or analyze the raw header before the response is ultimately delivered to the HTTP client.

This method will set a cookie with the given name that has an expiration time in the past; this will prompt the HTTP client to invalidate and remove the client-side cookie. Optionally, you may also pass a key/value array as the second argument. If the "domain" key is present in this array, only the Cookie with the given name AND domain will be removed. The invalidating cookie sent with this response will adopt all properties of the second argument.

Parameters

$name
string
$name The name of the cookie
$value
array
$value Properties for cookie including: value, expire, path, domain, secure, httponly
public
# redirect( string $url, integer $status = 302 )

Redirect

Redirect

This method prepares this response to return an HTTP Redirect response to the HTTP client.

Parameters

$url
string
$url The redirect destination
$status
integer
$status The redirect HTTP status code
public boolean
# isEmpty( )

Helpers: Empty?

Helpers: Empty?

Returns

boolean
public boolean
# isInformational( )

Helpers: Informational?

Helpers: Informational?

Returns

boolean
public boolean
# isOk( )

Helpers: OK?

Helpers: OK?

Returns

boolean
public boolean
# isSuccessful( )

Helpers: Successful?

Helpers: Successful?

Returns

boolean
public boolean
# isRedirect( )

Helpers: Redirect?

Helpers: Redirect?

Returns

boolean
public boolean
# isRedirection( )

Helpers: Redirection?

Helpers: Redirection?

Returns

boolean
public boolean
# isForbidden( )

Helpers: Forbidden?

Helpers: Forbidden?

Returns

boolean
public boolean
# isNotFound( )

Helpers: Not Found?

Helpers: Not Found?

Returns

boolean
public boolean
# isClientError( )

Helpers: Client error?

Helpers: Client error?

Returns

boolean
public boolean
# isServerError( )

Helpers: Server Error?

Helpers: Server Error?

Returns

boolean
public
# offsetExists( mixed $offset )

Array Access: Offset Exists

Array Access: Offset Exists

Implementation of

ArrayAccess::offsetExists()
public
# offsetGet( mixed $offset )

Array Access: Offset Get

Array Access: Offset Get

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( mixed $offset, mixed $value )

Array Access: Offset Set

Array Access: Offset Set

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( mixed $offset )

Array Access: Offset Unset

Array Access: Offset Unset

Implementation of

ArrayAccess::offsetUnset()
public
# count( )

Countable: Count

Countable: Count

Implementation of

Countable::count()
public Slim\Http\Headers
# getIterator( )

Get Iterator

Get Iterator

This returns the contained \Slim\Http\Headers instance which is itself iterable.

Returns

Slim\Http\Headers

Implementation of

IteratorAggregate::getIterator()
public static string|null
# getMessageForCode( mixed $status )

Get message for HTTP status code

Get message for HTTP status code

Returns

string|null
Properties summary
protected integer $status
#

HTTP status code

HTTP status code

protected Slim\Http\Headers $header
#

List of HTTP response headers

List of HTTP response headers

protected string $body
#

HTTP response body

HTTP response body

protected integer $length
#

Length of HTTP response body

Length of HTTP response body

protected static array $messages array( //Informational 1xx 100 => '100 Continue', 101 => '101 Switching Protocols', //Successful 2xx 200 => '200 OK', 201 => '201 Created', 202 => '202 Accepted', 203 => '203 Non-Authoritative Information', 204 => '204 No Content', 205 => '205 Reset Content', 206 => '206 Partial Content', //Redirection 3xx 300 => '300 Multiple Choices', 301 => '301 Moved Permanently', 302 => '302 Found', 303 => '303 See Other', 304 => '304 Not Modified', 305 => '305 Use Proxy', 306 => '306 (Unused)', 307 => '307 Temporary Redirect', //Client Error 4xx 400 => '400 Bad Request', 401 => '401 Unauthorized', 402 => '402 Payment Required', 403 => '403 Forbidden', 404 => '404 Not Found', 405 => '405 Method Not Allowed', 406 => '406 Not Acceptable', 407 => '407 Proxy Authentication Required', 408 => '408 Request Timeout', 409 => '409 Conflict', 410 => '410 Gone', 411 => '411 Length Required', 412 => '412 Precondition Failed', 413 => '413 Request Entity Too Large', 414 => '414 Request-URI Too Long', 415 => '415 Unsupported Media Type', 416 => '416 Requested Range Not Satisfiable', 417 => '417 Expectation Failed', 422 => '422 Unprocessable Entity', 423 => '423 Locked', //Server Error 5xx 500 => '500 Internal Server Error', 501 => '501 Not Implemented', 502 => '502 Bad Gateway', 503 => '503 Service Unavailable', 504 => '504 Gateway Timeout', 505 => '505 HTTP Version Not Supported' )
#

HTTP response codes and messages

HTTP response codes and messages

GeoApi API documentation generated by ApiGen 2.8.0