Overview

Namespaces

  • None
  • Wei
    • Validator

Classes

  • Apc
  • App
  • ArrayCache
  • Asset
  • Base
  • BaseCache
  • BaseController
  • Bicache
  • Cache
  • Config
  • Cookie
  • Couchbase
  • Counter
  • Db
  • DbCache
  • E
  • Env
  • Error
  • FileCache
  • Gravatar
  • Http
  • Lock
  • Logger
  • Memcache
  • Memcached
  • MongoCache
  • Password
  • PhpError
  • PhpFileCache
  • Pinyin
  • Record
  • Redis
  • Request
  • Response
  • Router
  • SafeUrl
  • Session
  • Soap
  • T
  • Ua
  • Upload
  • Url
  • Uuid
  • Validate
  • View
  • WeChatApp
  • Wei
  • Overview
  • Namespace
  • Class

Class Response

A service that handles the HTTP response data

Wei\Base
Extended by Wei\Response
Namespace: Wei
Author: Twin Huang twinhuang@qq.com
Located at Response.php
Methods summary
public
# __invoke( string $content = null, integer $status = null )

Send response header and content

Send response header and content

Parameters

$content
$status

Returns


$this
public
# send( string $content = null, integer $status = null )

Send response header and content

Send response header and content

Parameters

$content
$status

Returns


$this
public
# setContent( mixed $content )

Set response content

Set response content

Parameters

$content

Returns


$this
public mixed
# getContent( )

Get response content

Get response content

Returns

mixed
public
# sendContent( )

Send response content

Send response content

Returns


$this
public
# setStatusCode( integer $code, string|null $text = null )

Set the header status code

Set the header status code

Parameters

$code
The status code
$text
The status text

Returns


$this
public integer
# getStatusCode( )

Get the status code

Get the status code

Returns

integer
public
# setVersion( string $version )

Set the HTTP version

Set the HTTP version

Parameters

$version
The HTTP version

Returns


$this
public string
# getVersion( )

Get the HTTP version

Get the HTTP version

Returns

string
public
# setHeader( string $name, string|array $values = null, boolean $replace = true )

Set the header string

Set the header string

Parameters

$name
The header name
$values
The header values
$replace
Whether replace the exists values or not

Returns


$this
public mixed
# getHeader( string $name, mixed $default = null, boolean $first = true )

Get the header string

Get the header string

Parameters

$name
The header name
$default
The default value
$first
Return the first element or the whole header values

Returns

mixed
public
# removeHeader( string $name )

Remove header by specified name

Remove header by specified name

Parameters

$name
The header name

Returns


$this
public boolean
# sendHeader( )

Send HTTP headers, including HTTP status, raw headers and cookies

Send HTTP headers, including HTTP status, raw headers and cookies

Returns

boolean
If the header has been seen, return false, otherwise, return true
protected
# sendRawHeader( string $header )

Send a raw HTTP header

Send a raw HTTP header

If in unit test mode, the response will store header string into sentHeaders property without send it for testing purpose

Parameters

$header
public boolean
# isHeaderSent( string & $file = null, integer & $line = null )

Checks if or where headers have been sent

Checks if or where headers have been sent

If NOT in unit test mode and the optional file and line parameters are set, isHeaderSent() will put the PHP source file name and line number where output started in the file and line variables

Parameters

$file
$line
The line number where the output started

Returns

boolean

Link

http://php.net/manual/en/function.headers-sent.php
public mixed
# getCookie( string $key, mixed $default = null )

Get response cookie

Get response cookie

Parameters

$key
The name of cookie
$default
The default value when cookie not exists

Returns

mixed
public
# setCookie( string $key, mixed $value, array $options = array() )

Set response cookie

Set response cookie

Parameters

$key
The name of cookie
$value
The value of cookie
$options
The options of cookie

Returns


$this
public
# removeCookie( string $key )

Remove response cookie

Remove response cookie

Parameters

$key
The name of cookie

Returns


$this
public
# sendCookie( )

Send cookie

Send cookie

Returns


$this
public string
# __toString( )

Returns response status, headers and content as string

Returns response status, headers and content as string

Returns

string
public string
# getHeaderString( )

Returns response header as string

Returns response header as string

Returns

string
public
# setRedirectView( string $redirectView )

Set redirect view file

Set redirect view file

Parameters

$redirectView
The view file

Returns


$this

Throws

RuntimeException
When view file not found
public
# redirect( string $url = null, integer $statusCode = 302, array $options = array() )

Send a redirect response

Send a redirect response

Parameters

$url
The url redirect to
$statusCode
The response status code
$options
The redirect wei options

Returns


$this
public
# json( mixed $data, boolean $jsonp = false )

Response JSON or JSONP format string

Response JSON or JSONP format string

Parameters

$data
The variable to be convert to JSON string
$jsonp
Whether allow response json format on demand

Returns


$this
public
# jsonp( mixed $data )

Response JSONP format string

Response JSONP format string

Parameters

$data

Returns


$this
public
# flush( string $content = null )

Flushes content to browser immediately

Flushes content to browser immediately

Parameters

$content

Returns


$this
public
# download( string $file = null, array $downloadOptions = array() )

Send file download response

Send file download response

Parameters

$file
The path of file
$downloadOptions
The download options

Returns


$this

Throws

RuntimeException
When file not found
Methods inherited from Wei\Base
__call(), __construct(), __get(), getOption(), setOption()
Properties summary
protected array $statusTexts

Common use HTTP status code and text

Common use HTTP status code and text

# array( // Successful Requests 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', // Redirects 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', // Client Errors 401 => 'Unauthorized', 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', // Server Errors 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported' )
protected string $version

The HTTP version, current is 1.0 or 1.1

The HTTP version, current is 1.0 or 1.1

# '1.1'
protected integer $statusCode

The status code

The status code

# 200
protected string $statusText

The status text for status code

The status text for status code

# 'OK'
protected string $content

The response content

The response content

#
protected array $headers

The response headers

The response headers

# array()
protected array $sentHeaders

The sent response headers

The sent response headers

# array()
protected array $cookies

The response cookies

The response cookies

# array()
protected array $cookieOption

The cookie options

The cookie options

Name Type Description
expires int The lifetime of cookie (seconds)
path string The path on the server in which the cookie will be available on
domain string The domain that the cookie is available to
secure bool Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client
httpOnly bool When TRUE the cookie will be made accessible only through the HTTP protocol
raw bool Whether send a cookie without urlencoding the cookie value

Link

http://php.net/manual/en/function.setcookie.php
# array( 'expires' => 864000, 'path' => '/', 'domain' => null, 'secure' => false, 'httpOnly' => false, 'raw' => false, )
protected array $downloadOption

The download options

The download options

Name Type Description
type string The HTTP content type
disposition string The type of disposition, could be "attachment" or "inline",
filename string The file name to display in download dialog

When disposition is "inline", the browser will try to open file within the browser, while "attachment" will force it to download

Link

http://stackoverflow.com/questions/1395151/content-dispositionwhat-are-the-differences-between-inline-and-attachment
# array( 'type' => 'application/x-download', 'disposition' => 'attachment', 'filename' => null, )
protected boolean $unitTest

Whether in unit test mode

Whether in unit test mode

# false
protected string $redirectView

The custom redirect view file

The custom redirect view file

#
protected integer $redirectWait

The seconds to wait before redirect

The seconds to wait before redirect

# 0
protected callable $beforeSend

The callback executes before send response

The callback executes before send response

#
protected callable $afterSend

The callback executes after sent response

The callback executes after sent response

#
Properties inherited from Wei\Base
$providers, $wei
Magic properties summary
public Wei\Logger $logger

The logger service

public Wei\Request $request

The request service

Wei Framework API documentation generated by ApiGen