Documentation

Rest
in package

Manage Rest API request / response

Tags
example

Example :

self::init();
self::checkParams(['id']);
try{
    self::renderSuccess();
} catch(Exception $e){
    self::renderError($e->getMessage());
}

Table of Contents

$count  : int
Current count relative to the page and limit ($limit*$currentpage)
$currentPage  : int
Current page number
$limit  : int
Limit of result by page
$nbPage  : int
The total of the request page
$params  : array<string|int, mixed>
Request post data
checkParams()  : void
Check the presence of required params
checkReferer()  : void
Check if the referer corresponding to the same server
checkRequest()  : void
Check if the request is a XMLHttpRequest
init()  : void
Check the conformity of the request and get the post data
render()  : void
Normalize data to render
renderError()  : void
Rest response on error
renderJson()  : void
Rest response
renderSuccess()  : void
Rest response on success

Properties

$count

Current count relative to the page and limit ($limit*$currentpage)

public static int $count = 0

$currentPage

Current page number

public static int $currentPage = 1

$limit

Limit of result by page

public static int $limit = 20

$nbPage

The total of the request page

public static int $nbPage = 1

$params

Request post data

public static array<string|int, mixed> $params = []

Methods

checkParams()

Check the presence of required params

public static checkParams([null|array<string|int, mixed> $list = [] ][, null|bool $allowEmpty = false ]) : void
Parameters
$list : null|array<string|int, mixed> = []
$allowEmpty : null|bool = false
Return values
void

checkReferer()

Check if the referer corresponding to the same server

public static checkReferer() : void
Return values
void

checkRequest()

Check if the request is a XMLHttpRequest

public static checkRequest() : void
Return values
void

init()

Check the conformity of the request and get the post data

public static init([null|bool $restrict = true ]) : void
Parameters
$restrict : null|bool = true
Return values
void

render()

Normalize data to render

public static render(bool $result[, null|array<string|int, mixed> $data = [] ]) : void
Parameters
$result : bool

Specify is the response is on success or error

$data : null|array<string|int, mixed> = []
Return values
void

renderError()

Rest response on error

public static renderError([mixed $error = '' ]) : void
Parameters
$error : mixed = ''
Return values
void

renderJson()

Rest response

public static renderJson([null|array<string|int, mixed> $params = [] ]) : void
Parameters
$params : null|array<string|int, mixed> = []
Return values
void

renderSuccess()

Rest response on success

public static renderSuccess([mixed $data = '' ]) : void
Parameters
$data : mixed = ''
Return values
void

Search results