Response
extends Result
in package
Define common HTTP response object
This class implements an extended implementation of the main system result object, it is designed to serve http requests.
Tags
Table of Contents
- $code : int
- The http response codes
- $content_type : string|null
- Buffer for content type
- $cookie : array<string|int, mixed>
- Cookie buffer
- $filename : string|null
- File name for attachment
- $filepath : string|null
- File path for attachment
- $header : array<string|int, mixed>
- List of additional header fields
- $redirect : string|array<string|int, mixed>
- Is redirect
- $type : int
- The response type
- __construct() : mixed
- Construct response construct a new instance of the response object
- AddHeader() : void
- Add extra outbound header add a set of header to the local ones
- CustomContentType() : string|null
- Get custom response type
- FileName() : string|null
- Get the file name of attachment
- FilePath() : string|null
- Get file path of attachment
- GetCode() : int|null
- Get the response code
- GetCookies() : array<string|int, mixed>
- Get the set cookies for further use
- GetHeader() : array<string|int, mixed>
- get outbound header get a set of header to the local ones
- GetRedirect() : string|array<string|int, mixed>|null
- Is a redirect?
- IsAttachment() : bool
- Redirect() : void
- Set redirect
- Serialize() : array<string|int, mixed>|null
- Serialize Convert to regular array
- SetAttachment() : bool
- Send as file attachment
- SetCookie() : void
- Set a cookie
- SetErrorCode() : Response
- Set error response code
- SetSuccess() : void
- Set http success code
- TranslateAttachment() : string
- Type() : int|Response
- Expose type getter / setter
- getTranslation() : string
Properties
$code
The http response codes
private
int
$code
= 0
$content_type
Buffer for content type
private
string|null
$content_type
= null
$cookie
Cookie buffer
private
array<string|int, mixed>
$cookie
= array()
$filename
File name for attachment
private
string|null
$filename
= null
$filepath
File path for attachment
private
string|null
$filepath
= null
$header
List of additional header fields
private
array<string|int, mixed>
$header
= array()
$redirect
Is redirect
private
string|array<string|int, mixed>
$redirect
= null
$type
The response type
private
int
$type
= FAA_RESPONSE_TYPE_JSON
Methods
__construct()
Construct response construct a new instance of the response object
public
__construct([bool $status = false ][, string $message = "" ][, mixed $values = array() ][, mixed $secondary = array() ]) : mixed
Parameters
- $status : bool = false
-
The boolean state of the initialised status
- $message : string = ""
-
The first message
- $values : mixed = array()
-
The first values
- $secondary : mixed = array()
-
The secondary values
Return values
mixed —AddHeader()
Add extra outbound header add a set of header to the local ones
public
AddHeader(array<string|int, mixed> $header) : void
Parameters
- $header : array<string|int, mixed>
-
A list of header
Return values
void —CustomContentType()
Get custom response type
public
CustomContentType() : string|null
Return values
string|null —FileName()
Get the file name of attachment
public
FileName() : string|null
Return values
string|null —FilePath()
Get file path of attachment
public
FilePath() : string|null
Return values
string|null —GetCode()
Get the response code
public
GetCode() : int|null
Return values
int|null —GetCookies()
Get the set cookies for further use
public
GetCookies() : array<string|int, mixed>
Return values
array<string|int, mixed> —GetHeader()
get outbound header get a set of header to the local ones
public
GetHeader() : array<string|int, mixed>
Return values
array<string|int, mixed> —a list of header entries
GetRedirect()
Is a redirect?
public
GetRedirect() : string|array<string|int, mixed>|null
Return values
string|array<string|int, mixed>|null —IsAttachment()
public
IsAttachment() : bool
Return values
bool —Redirect()
Set redirect
public
Redirect(string|array<string|int, mixed> $path[, bool $direct = false ]) : void
Redirect to this path. The url will be interpreted as internal link by default. To use external targets, set the second argument to true
Parameters
- $path : string|array<string|int, mixed>
-
The absolute redirect path or an array with path and query arguments
- $direct : bool = false
-
Set as direct response type
Return values
void —Serialize()
Serialize Convert to regular array
public
Serialize([string|null $language = null ]) : array<string|int, mixed>|null
Parameters
- $language : string|null = null
-
The target language or null
Return values
array<string|int, mixed>|null —SetAttachment()
Send as file attachment
public
SetAttachment(string $path, string $name[, int $mode = FAA_RESPONSE_TYPE_ATTACHMENT ]) : bool
Set outbound parse mode to attachment. Query parameters and anchor parts will be stripped automatically
Parameters
- $path : string
-
The absolute file path
- $name : string
-
The file name
- $mode : int = FAA_RESPONSE_TYPE_ATTACHMENT
-
The file mime type handling option, either FAA_RESPONSE_TYPE_ATTACHMENT or, FAA_RESPONSE_TYPE_ATTACHMENT_AUTO
Return values
bool —SetCookie()
Set a cookie
public
SetCookie(string $name, string|null $val, array<string|int, mixed> $array) : void
Parameters
- $name : string
- $val : string|null
- $array : array<string|int, mixed>
Return values
void —SetErrorCode()
Set error response code
public
SetErrorCode([int $code = 500 ][, bool $status = false ]) : Response
This method is chainable
Parameters
- $code : int = 500
-
Http response code, should be of 400 - 599
- $status : bool = false
-
Override status of this call
Return values
Response —SetSuccess()
Set http success code
public
SetSuccess([int $code = 201 ][, string|null $path = null ]) : void
Can be used to set a paths for the next call as well Set the status of the instance to true
Parameters
- $code : int = 201
-
The response code, should be of 200 - 299
- $path : string|null = null
-
Can be set to a redirect path e.g. after POST witch created result
Return values
void —TranslateAttachment()
public
TranslateAttachment(Request $request) : string
Parameters
- $request : Request
Return values
string —Type()
Expose type getter / setter
public
Type([int|null $type = null ][, string|null $value = null ]) : int|Response
Provide an interface to the local response content type. This method is chainable
The type is one of: FAA_RESPONSE_TYPE_JSON, FAA_RESPONSE_TYPE_HTML, FAA_RESPONSE_TYPE_ATTACHMENT, FAA_RESPONSE_TYPE_CORS, FAA_RESPONSE_TYPE_DIRECT_REDIRECT, FAA_RESPONSE_TYPE_XML, FAA_RESPONSE_TYPE_TXT, FAA_RESPONSE_TYPE_CUSTOM, FAA_RESPONSE_TYPE_ATTACHMENT_AUTO, FAA_RESPONSE_TYPE_ATTACHMENT_XML
Parameters
- $type : int|null = null
-
The system response type
- $value : string|null = null
-
The system response content type as string
Return values
int|Response —The system response type or void in setter mode
getTranslation()
protected
getTranslation(string $data, string $l[, string $type = 'code' ][, string $src = '' ]) : string
Parameters
- $data : string
- $l : string
- $type : string = 'code'
- $src : string = ''