inc\classes\api.phpView Source

Show: PublicProtectedPrivateinherited
Table of Contents
Class
Author
Sergey Dilong  
License
GPL-2.0  
Package
Temply-Account\Core  

Constants

>VConstant  RESPONSE_TYPE = "JSON"
Response type
Package
Temply-Account\Core  

\api

Package: Temply-Account\Core
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

Author
Sergey Dilong  
License
GPL-2.0  

Methods

methodprivateDataAsJSON() : void
static

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

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

methodprivateDataAsXML() : void
static

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

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

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

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
NameTypeDescription
$astring

Comma-separated (with spaces) required keys

$barray | string

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

Returns
TypeDescription
booleanTrue if all required params are presented, false - if not.
methodpublicerror(integer $l, array<mixed,mixed> $o = array()) : void
static

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
NameTypeDescription
$linteger

Code number

$oarray<mixed,mixed>

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

Details
See
Method, which generates the error  
methodpublicgetInputData() : void
static

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)

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

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
NameTypeDescription
$linteger

Code number

$oarray<mixed,mixed>

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

Returns
TypeDescription
arrayError array to display
Details
See
[Recommended] Throwing Exceptions  
See
Setting errors  
methodpublicrequired(string $a, array | string $b = 'NULL') : boolean
static

Public method for check_required

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

Parameters
NameTypeDescription
$astring

Comma-separated (with spaces) required keys

$barray | string

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

Returns
TypeDescription
booleanTrue if everything is OK
Throws
ExceptionDescription
\apiException[102] If there's no one or more required keys
Details
Example
Fields could be required by statements  
Documentation was generated by phpDocumentor v2.9.0.