\api

Controls output flow, error messages displaying

Basically it's used as a pallet of functions for api.php to don't clutter up global namespace

Summary

Methods
Properties
Constants
required()
get_error()
error()
getInputData()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
check_required()
DataAsJSON()
DataAsXML()
No private properties found
N/A

Methods

required()

required(string  $a, array|string  $b = 'NULL') : boolean

Public method for check_required

A mirror for check_required Logic of initial function, but instead of false it throws exception

Parameters

string $a

Comma-separated (with spaces) required keys

array|string $b

Array to be checked. If === 'NULL' - it checks $secure global

Throws

\apiException

[102] If there's no one or more required keys

Returns

boolean —

True if everything is OK

Examples

Fields could be required by statements
// Require variables by statements
if (isset($secure['require_test'])) { // If client wants to test field-requiring
    api::required("int_value, str_value");
    //       ....            ^ Space is important
}

get_error()

get_error(integer  $l, array<mixed,mixed>  $o = array()) : array

Loads error from error library

Gets error from /classes/help/errors Finds error info by code. First number - error section, others - error number. If there's no such code it fallbacks to error 100. If you would like to throw an error use Custom Exception class or a class method

Parameters

integer $l

Code number

array<mixed,mixed> $o

Array, which will be returned as extended key with the error

Returns

array —

Error array to display

error()

error(integer  $l, array<mixed,mixed>  $o = array()) : void

Get and terminate execution of API method with an error

If you would like to throw any errors I strongly recommend you to use Custom Exception class

Parameters

integer $l

Code number

array<mixed,mixed> $o

Array, which will be returned as extended key with the error

getInputData()

getInputData() : void

Define preferred data type for client

This method decides which encoding could be accepted by client. For now supported types are JSON and XML (but XML doesn't supported by fatal errors)

check_required()

check_required(string  $a, array|string  $b = 'NULL') : boolean

Checks if an array has all required fields

By default checks $secure array, but you mustn't use it directly from here self::check_required("field1, field2", ["field1" => 1, "field2" => 2])

Parameters

string $a

Comma-separated (with spaces) required keys

array|string $b

Array to be checked. If === 'NULL' - it checks $secure global

Returns

boolean —

True if all required params are presented, false - if not.

DataAsJSON()

DataAsJSON() : void

Decodes and merges input data if in POST-Raw JSON-encoded data was detected

Works with global variables, sets Content-Type: application/json header

DataAsXML()

DataAsXML() : void

Decodes and merges input data if in POST-Raw XML-encoded data was detected

Works with global variables, sets Content-Type: application/xml header