Documentation

RESTful
in package

[$api = $this->core->loadClass('RESTful');] Class CFI to handle APIs. It is been used in Core APIs last_update: 20200502

Table of Contents

Properties

$apiName  : mixed
$auth  : mixed
$code  : mixed
$codeLib  : mixed
$codeLibError  : mixed
$contentTypeReturn  : mixed
$core  : Core7|null
$dv  : DataValidation
$error  : mixed
$errorMsg  : mixed
$extra_headers  : mixed
$formParams  : mixed
$message  : mixed
$method  : mixed
$ok  : mixed
$org_id  : mixed
$params  : mixed
$rawData  : mixed
$referer  : mixed
$requestHeaders  : mixed
$returnData  : mixed
$rewrite  : mixed
$service  : mixed
$serviceParam  : mixed
$url  : mixed
$urlParams  : mixed

Methods

__construct()  : mixed
addCodeLib()  : mixed
Add a code for JSON output
addHeader()  : mixed
addReturnData()  : mixed
Add a new record to be returned
checkBasicAuthSecurity()  : bool
Check if an Authorization-Header Basic has been sent and match with any core.system.authorizations config var.
checkCloudFrameWorkSecurity()  : mixed
checkFormParamsFromModel()  : bool|void
Evaluate $data and if it is correct using $model. It uses the class DataValidation
checkMandatoryFormParam()  : false|mixed|string
Validate a $this->formParams[$key] value as mandatory
checkMandatoryFormParams()  : bool|void
Check if it is received mandatory params
checkMandatoryParam()  : bool
Validate that a specific parameter exist: /{end-point}/parameter[0]/parameter[1]/parameter[2]/.
checkMethod()  : mixed
existBasicAuth()  : mixed
getCloudFrameWorkSecurityInfo()  : mixed
getCodeLib()  : mixed
Return the structure of $code in $this->codeLib if it exists
getCodeLibError()  : int|mixed
Return the structure of $code in $this->codeLibError if it exists
getFormParamater()  : mixed
Return the value of $this->formParams[$var]. Return null if $var does not exist
getHeader()  : string
Return the user header key value. In PHP those are $_SERVER["HTTP_$headerKey}"].
getHeaderAuthorization()  : null|string
Returns the info of the header Authorization if it exists, otherwise null
getHeaders()  : array<string|int, mixed>
Return all the header keys sent by the user. In PHP those are $_SERVER['HTTP_{varname}']
getHeadersToResend()  : mixed
getRequestHeader()  : mixed
getResponseHeader()  : mixed
Translate Error codes into headers.
getResponseHeaders()  : mixed
getReturnCode()  : int|string
Return the code applied with setError and defined in __codes
getReturnStatus()  : mixed
getUrlPathParamater()  : mixed
Return the value of $this->params[$var]. Return null if $var does not exist
rewriteReturnResponse()  : mixed
send()  : mixed
Echo the result
sendCorsHeaders()  : mixed
Setup CORS Headers to allow Ajax Web Calls
sendHeaders()  : mixed
setAuth()  : mixed
setError()  : mixed
Set and error to be return in JSON format with status $returnStatus
setErrorFromCodelib()  : mixed
Set an error using $code
setReturnCode()  : mixed
Assign a code
setReturnData()  : mixed
Init the data to be returned
setReturnFormat()  : mixed
setReturnResponse()  : mixed
setReturnStatus()  : mixed
updateReturnResponse()  : mixed
useFunction()  : bool
Execute a method if $method is defined.
validatePostData()  : bool
Check the form paramters received based in a json model
validatePutData()  : bool|void
Validate data received in $this->formParams to update a record
validateValue()  : mixed

Properties

$codeLibError

public mixed $codeLibError = []

$contentTypeReturn

public mixed $contentTypeReturn = 'JSON'

$errorMsg

public mixed $errorMsg = []

$extra_headers

public mixed $extra_headers = []

$formParams

public mixed $formParams = array()

$params

public mixed $params = array()

$rawData

public mixed $rawData = array()

$referer

public mixed $referer = \null

$requestHeaders

public mixed $requestHeaders = array()

$returnData

public mixed $returnData = \null

$serviceParam

public mixed $serviceParam = ''

$urlParams

public mixed $urlParams = ''

Methods

__construct()

public __construct(Core7 &$core[, mixed $apiUrl = '/h/api' ]) : mixed
Parameters
$core : Core7
$apiUrl : mixed = '/h/api'

addCodeLib()

Add a code for JSON output

public addCodeLib( $code,  $msg[, int $error = 400 ][, null $model = null ]) : mixed
Parameters
$code :
$msg :
$error : int = 400
$model : null = null

addHeader()

public addHeader(mixed $key, mixed $value) : mixed
Parameters
$key : mixed
$value : mixed

addReturnData()

Add a new record to be returned

public addReturnData( $value) : mixed
Parameters
$value :

checkBasicAuthSecurity()

Check if an Authorization-Header Basic has been sent and match with any core.system.authorizations config var.

public checkBasicAuthSecurity([string $id = '' ]) : bool
Parameters
$id : string = ''
Return values
bool

checkCloudFrameWorkSecurity()

public checkCloudFrameWorkSecurity([mixed $time = 0 ][, mixed $id = '' ]) : mixed
Parameters
$time : mixed = 0
$id : mixed = ''

checkFormParamsFromModel()

Evaluate $data and if it is correct using $model. It uses the class DataValidation

public checkFormParamsFromModel( &$model[, bool $all = true ][, string $codelibbase = '' ][, null &$data = null ][, array<string|int, mixed> &$dictionaries = [] ]) : bool|void
Parameters
$model :
$all : bool = true
$codelibbase : string = ''
$data : null = null
$dictionaries : array<string|int, mixed> = []
Return values
bool|void

checkMandatoryFormParam()

Validate a $this->formParams[$key] value as mandatory

public checkMandatoryFormParam( $key[, string $msg = '' ][, array<string|int, mixed> $values = [] ][, int $min_length = 1 ][, null $code = null ]) : false|mixed|string
Parameters
$key :
$msg : string = ''
$values : array<string|int, mixed> = []
$min_length : int = 1
$code : null = null
Return values
false|mixed|string

checkMandatoryFormParams()

Check if it is received mandatory params

public checkMandatoryFormParams(array<string|int, mixed> $keys) : bool|void
Parameters
$keys : array<string|int, mixed>

with format: [key1,kye2,..] or [[key1,msg,[allowed,values],min_length],[]]

Return values
bool|void

checkMandatoryParam()

Validate that a specific parameter exist: /{end-point}/parameter[0]/parameter[1]/parameter[2]/.

public checkMandatoryParam( $pos[, string $msg = '' ][, array<string|int, mixed> $validation = [] ][, null $code = null ]) : bool

.

Parameters
$pos :
$msg : string = ''
$validation : array<string|int, mixed> = []
$code : null = null
Return values
bool

checkMethod()

public checkMethod(mixed $methods[, mixed $msg = '' ]) : mixed
Parameters
$methods : mixed
$msg : mixed = ''

existBasicAuth()

public existBasicAuth() : mixed

getCloudFrameWorkSecurityInfo()

public getCloudFrameWorkSecurityInfo() : mixed

getCodeLib()

Return the structure of $code in $this->codeLib if it exists

public getCodeLib( $code) : mixed
Parameters
$code :

getCodeLibError()

Return the structure of $code in $this->codeLibError if it exists

public getCodeLibError( $code) : int|mixed
Parameters
$code :
Return values
int|mixed

getFormParamater()

Return the value of $this->formParams[$var]. Return null if $var does not exist

public getFormParamater(string $var) : mixed
Parameters
$var : string
Tags
retun

null|mixed

getHeader()

Return the user header key value. In PHP those are $_SERVER["HTTP_$headerKey}"].

public getHeader(string $headerKey) : string
Parameters
$headerKey : string

The name of the header. Vars like X-VAR or X_VAR are treated like the same

Return values
string

If the key does not exist return empty string

getHeaderAuthorization()

Returns the info of the header Authorization if it exists, otherwise null

public getHeaderAuthorization() : null|string
Return values
null|string

getHeaders()

Return all the header keys sent by the user. In PHP those are $_SERVER['HTTP_{varname}']

public getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

getHeadersToResend()

public getHeadersToResend([mixed $extra_headers = null ]) : mixed
Parameters
$extra_headers : mixed = null

getRequestHeader()

public getRequestHeader(mixed $str) : mixed
Parameters
$str : mixed

getResponseHeader()

Translate Error codes into headers.

public getResponseHeader() : mixed

Useful info: https://restfulapi.net/http-status-codes/

getResponseHeaders()

public getResponseHeaders() : mixed

getReturnCode()

Return the code applied with setError and defined in __codes

public getReturnCode() : int|string
Return values
int|string

getReturnStatus()

public getReturnStatus() : mixed

getUrlPathParamater()

Return the value of $this->params[$var]. Return null if $var does not exist

public getUrlPathParamater(int $var) : mixed
Parameters
$var : int
Tags
retun

null|mixed

rewriteReturnResponse()

public rewriteReturnResponse(mixed $response) : mixed
Parameters
$response : mixed

send()

Echo the result

public send([bool $pretty = false ][, bool $return = false ][, array<string|int, mixed> $argv = [] ]) : mixed
Parameters
$pretty : bool = false

if true, returns the JSON string with JSON_PRETTY_PRINT

$return : bool = false

if true, instead to echo then return the output.

$argv : array<string|int, mixed> = []

if we are running from a terminal it will receive the command line args.

sendCorsHeaders()

Setup CORS Headers to allow Ajax Web Calls

public sendCorsHeaders([string $methods = 'GET,POST,PUT' ][, string $origin = '' ][, string $allow_extra_headers = '' ]) : mixed
Parameters
$methods : string = 'GET,POST,PUT'
$origin : string = ''
$allow_extra_headers : string = ''

If you need to add headers to be allowed use this variable.

sendHeaders()

public sendHeaders() : mixed

setAuth()

public setAuth(mixed $val[, mixed $msg = '' ]) : mixed
Parameters
$val : mixed
$msg : mixed = ''

setError()

Set and error to be return in JSON format with status $returnStatus

public setError(mixed $error[, int $returnStatus = 400 ][, mixed $returnCode = null ][, string $message = '' ]) : mixed
Parameters
$error : mixed

Error to show. It can be a string or and array

$returnStatus : int = 400

integer >=200. 400 by default

$returnCode : mixed = null

optional returnCode

$message : string = ''

setErrorFromCodelib()

Set an error using $code

public setErrorFromCodelib( $code[, string $extramsg = '' ]) : mixed
Parameters
$code :
$extramsg : string = ''
Tags
retun

void

setReturnCode()

Assign a code

public setReturnCode( $code) : mixed
Parameters
$code :

setReturnData()

Init the data to be returned

public setReturnData( $data) : mixed
Parameters
$data :

setReturnFormat()

public setReturnFormat(mixed $method) : mixed
Parameters
$method : mixed

setReturnResponse()

public setReturnResponse(mixed $response) : mixed
Parameters
$response : mixed

setReturnStatus()

public setReturnStatus(mixed $status) : mixed
Parameters
$status : mixed

updateReturnResponse()

public updateReturnResponse(mixed $response) : mixed
Parameters
$response : mixed

useFunction()

Execute a method if $method is defined.

public useFunction(string $method) : bool
Parameters
$method : string

name of the method

Return values
bool

validatePostData()

Check the form paramters received based in a json model

public validatePostData(array<string|int, mixed> $model[, string $codelibbase = 'error-form-params' ][, null &$data = null ][, mixed &$dictionaries = [] ]) : bool
Parameters
$model : array<string|int, mixed>
$codelibbase : string = 'error-form-params'
$data : null = null
$dictionaries : mixed = []
Return values
bool

validatePutData()

Validate data received in $this->formParams to update a record

public validatePutData( $model[, string $codelibbase = 'error-form-params' ][, null &$data = null ][, array<string|int, mixed> &$dictionaries = [] ]) : bool|void
Parameters
$model :
$codelibbase : string = 'error-form-params'
$data : null = null
$dictionaries : array<string|int, mixed> = []
Return values
bool|void

validateValue()

public validateValue(string $field, mix $value, string $type[, string $validation = '' ][, string $msg_error = '' ]) : mixed
Parameters
$field : string
$value : mix
$type : string
$validation : string = ''
$msg_error : string = ''

        
On this page

Search results