\PhalApi_Response_JsonP

PhalApi_Response_JsonP JSON响应类

  • all of the reponse status, and format the result
  • 200 stands for success, while 400 stands for illegal request, and 500 stands for server internal error

Summary

Methods
Properties
Constants
setRet()
setData()
setMsg()
setDebug()
addHeaders()
output()
getResult()
getHeaders()
__construct()
No public properties found
No constants found
handleHeaders()
formatResult()
clearXss()
$ret
$data
$msg
$headers
$debug
$callback
N/A
No private methods found
No private properties found
N/A

Properties

$ret

$ret : integer

Type

integer — reponse return code, 200 stands for success, while 400 stands for illegal request, and 500 stands for server internal error

$data

$data : array

Type

array — result wait to be send to client

$msg

$msg : string

Type

string — error message to return

$headers

$headers : array

Type

array — reponse headers

$debug

$debug : array

Type

array — debug infomation

$callback

$callback : 

Type

Methods

setRet()

setRet(integer  $ret) : \PhalApi_Response

Set the response status

Parameters

integer $ret

response status, such as: 2xx, 4xx, 5xx

Returns

\PhalApi_Response

setData()

setData(\array/string  $data) : \PhalApi_Response

Set the response data

Parameters

\array/string $data

result data to client, we suggest return array data, not string data

Returns

\PhalApi_Response

setMsg()

setMsg(string  $msg) : \PhalApi_Response

Set the error message

Parameters

string $msg

error message

Returns

\PhalApi_Response

setDebug()

setDebug(string  $key, mixed  $value) : \PhalApi_Response

Set debug infomation

Parameters

string $key

debug key

mixed $value

debug data

Returns

\PhalApi_Response

addHeaders()

addHeaders(string  $key, string  $content) 

Add header

Parameters

string $key

header name

string $content

header content

output()

output() 

Ouput

getResult()

getResult() 

------------------ getter ------------------ *

getHeaders()

getHeaders(string  $key = NULL) : \string/array

Get Headers

Parameters

string $key

header name

Returns

\string/array —

return NULL when header not exists, and return all headers when $key is NULL

__construct()

__construct(string  $callback) 

Parameters

string $callback

JS回调函数名

handleHeaders()

handleHeaders(  $headers) 

------------------ internal functions ------------------ *

Parameters

$headers

formatResult()

formatResult(array  $result) 

Format result data

Parameters

array $result

reponse data to client

clearXss()

clearXss(  $callback) 

对回调函数进行跨站清除处理

  • 可使用白名单或者黑名单方式处理,由接口开发再实现

Parameters

$callback