inc\classes\api.php
- Author
- Sergey Dilong
- License
- GPL-2.0
- Package
- Temply-Account\Core
Constants
\api
Basically it's used as a pallet of functions for api.php to don't clutter up global namespace
- Author
- Sergey Dilong
- License
- GPL-2.0
Methods

DataAsJSON() : voidDecodes and merges input data if in POST-Raw JSON-encoded data was detected
Works with global variables, sets Content-Type: application/json header

DataAsXML() : voidDecodes and merges input data if in POST-Raw XML-encoded data was detected
Works with global variables, sets Content-Type: application/xml header

check_required(string $a, array | string $b = 'NULL') : booleanChecks 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])
| Name | Type | Description |
|---|---|---|
| $a | string | Comma-separated (with spaces) required keys |
| $b | array | string | Array to be checked. If === 'NULL' - it checks $secure global |
| Type | Description |
|---|---|
| boolean | True if all required params are presented, false - if not. |

error(integer $l, array<mixed,mixed> $o = array()) : voidGet 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
| Name | Type | Description |
|---|---|---|
| $l | integer | Code number |
| $o | array<mixed,mixed> | Array, which will be returned as |

getInputData() : voidDefine 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)

get_error(integer $l, array<mixed,mixed> $o = array()) : arrayLoads 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
| Name | Type | Description |
|---|---|---|
| $l | integer | Code number |
| $o | array<mixed,mixed> | Array, which will be returned as |
| Type | Description |
|---|---|
| array | Error array to display |

required(string $a, array | string $b = 'NULL') : booleanPublic method for check_required
A mirror for check_required Logic of initial function, but instead of false it throws exception
| Name | Type | Description |
|---|---|---|
| $a | string | Comma-separated (with spaces) required keys |
| $b | array | string | Array to be checked. If === 'NULL' - it checks $secure global |
| Type | Description |
|---|---|
| boolean | True if everything is OK |
| Exception | Description |
|---|---|
| \apiException | [102] If there's no one or more required keys |
- Example
- Fields could be required by statements