Overview
  • Namespace
  • Class

Namespaces

  • Slim
    • Exception
    • Handlers
      • Strategies
    • Http
    • Interfaces
      • Http

Classes

  • Body
  • Cookies
  • Environment
  • Headers
  • Message
  • Request
  • RequestBody
  • Response
  • Stream
  • UploadedFile
  • Uri

Class Response

Response

This class represents an HTTP response. It manages the response status, headers, and body according to the PSR-7 standard.

Slim\Http\Message implements Psr\Http\Message\MessageInterface
Extended by Slim\Http\Response implements Psr\Http\Message\ResponseInterface
Namespace: Slim\Http
Link: https://github.com/php-fig/http-message/blob/master/src/MessageInterface.php
Link: https://github.com/php-fig/http-message/blob/master/src/ResponseInterface.php
Located at Http/Response.php

Methods summary

public
# __construct( integer $status = 200, Slim\Interfaces\Http\HeadersInterface $headers = null, Psr\Http\Message\StreamInterface $body = null )

Create new HTTP response.

Create new HTTP response.

Parameters

$status
The response status code.
$headers
The response headers.
$body
The response body.
public
# __clone( )

This method is applied to the cloned object after PHP performs an initial shallow-copy. This method completes a deep-copy by creating new objects for the cloned object's internal reference pointers.

This method is applied to the cloned object after PHP performs an initial shallow-copy. This method completes a deep-copy by creating new objects for the cloned object's internal reference pointers.

public integer
# getStatusCode( )

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.

Returns

integer
Status code.
public static
# withStatus( integer $code, string $reasonPhrase = '' )

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, implementations MAY choose to default to the RFC 7231 or IANA recommended reason phrase for the response's status code.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated status and reason phrase.

Parameters

$code
The 3-digit integer result code to set.
$reasonPhrase

The reason phrase to use with the provided status code; if none is provided, implementations MAY use the defaults as suggested in the HTTP specification.

Returns

static

Throws

InvalidArgumentException
For invalid status code arguments.

Link

http://tools.ietf.org/html/rfc7231#section-6
http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
protected integer
# filterStatus( integer $status )

Filter HTTP status code.

Filter HTTP status code.

Parameters

$status
HTTP status code.

Returns

integer

Throws

InvalidArgumentException
If an invalid HTTP status code is provided.
public string
# getReasonPhrase( )

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

string
Reason phrase; must return an empty string if none present.

Link

http://tools.ietf.org/html/rfc7231#section-6
http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
public
# write( string $data )

Write data to the response body.

Write data to the response body.

Note: This method is not part of the PSR-7 standard.

Proxies to the underlying stream and writes the provided data to it.

Parameters

$data

Returns


$this
public static
# withRedirect( string|Psr\Http\Message\UriInterface $url, integer|null $status = null )

Redirect.

Redirect.

Note: This method is not part of the PSR-7 standard.

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

Parameters

$url
The redirect destination.
$status
The redirect HTTP status code.

Returns

static
public static
# withJson( mixed $data, integer $status = null, integer $encodingOptions = 0 )

Json.

Json.

Note: This method is not part of the PSR-7 standard.

This method prepares the response object to return an HTTP Json response to the client.

Parameters

$data
The data
$status
The HTTP status code.
$encodingOptions
Json encoding options

Returns

static

Throws

RuntimeException
public boolean
# isEmpty( )

Is this response empty?

Is this response empty?

Note: This method is not part of the PSR-7 standard.

Returns

boolean
public boolean
# isInformational( )

Is this response informational?

Is this response informational?

Note: This method is not part of the PSR-7 standard.

Returns

boolean
public boolean
# isOk( )

Is this response OK?

Is this response OK?

Note: This method is not part of the PSR-7 standard.

Returns

boolean
public boolean
# isSuccessful( )

Is this response successful?

Is this response successful?

Note: This method is not part of the PSR-7 standard.

Returns

boolean
public boolean
# isRedirect( )

Is this response a redirect?

Is this response a redirect?

Note: This method is not part of the PSR-7 standard.

Returns

boolean
public boolean
# isRedirection( )

Is this response a redirection?

Is this response a redirection?

Note: This method is not part of the PSR-7 standard.

Returns

boolean
public boolean
# isForbidden( )

Is this response forbidden?

Is this response forbidden?

Note: This method is not part of the PSR-7 standard.

Returns

boolean

Api

public boolean
# isNotFound( )

Is this response not Found?

Is this response not Found?

Note: This method is not part of the PSR-7 standard.

Returns

boolean
public boolean
# isClientError( )

Is this response a client error?

Is this response a client error?

Note: This method is not part of the PSR-7 standard.

Returns

boolean
public boolean
# isServerError( )

Is this response a server error?

Is this response a server error?

Note: This method is not part of the PSR-7 standard.

Returns

boolean
public string
# __toString( )

Convert response to string.

Convert response to string.

Note: This method is not part of the PSR-7 standard.

Returns

string

Methods inherited from Slim\Http\Message

__set(), getBody(), getHeader(), getHeaderLine(), getHeaders(), getProtocolVersion(), hasHeader(), withAddedHeader(), withBody(), withHeader(), withProtocolVersion(), withoutHeader()

Constants summary

string EOL

EOL characters used for HTTP response.

EOL characters used for HTTP response.

# "\r\n"

Properties summary

protected integer $status

Status code

Status code

# 200
protected string $reasonPhrase

Reason phrase

Reason phrase

# ''
protected static array $messages

Status codes and reason phrases

Status codes and reason phrases

# [ //Informational 1xx 100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', //Successful 2xx 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 3xx 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => '(Unused)', 307 => 'Temporary Redirect', 308 => 'Permanent Redirect', //Client Error 4xx 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 Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 421 => 'Misdirected Request', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 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 5xx 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', ]

Properties inherited from Slim\Http\Message

$body, $headers, $protocolVersion, $validProtocolVersions

API documentation generated by ApiGen