\TriTanError

Error API: Error Class

Based on WordPress error API. Container for checking for TriTan CMS errors and error messages. Return Error and use \TriTan\is_ttcms_error() to check if this class is returned. Many core TriTan CMS functions pass this class in the event of an error and if not handled properly will result in code errors.

Summary

Methods
Properties
Constants
__construct()
getErrorCodes()
getErrorCode()
getErrorMessages()
getErrorMessage()
getErrorData()
add()
addData()
remove()
$errors
$error_data
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$errors

$errors : array

Stores the list of errors.

Type

array

$error_data

$error_data : array

Stores the list of data for error codes.

Type

array

Methods

__construct()

__construct(string|integer  $code = '', string  $message = '', mixed  $data = '') 

Initialize the error.

If $code is empty, the other parameters will be ignored. When $code is not empty, $message will be used even if it is empty. The $data parameter will be used only if it is not empty.

Though the class is constructed with a single error code and message, multiple codes can be added using the add() method.

Parameters

string|integer $code

Error code

string $message

Error message

mixed $data

Optional. Error data.

getErrorCodes()

getErrorCodes() : array

Retrieve all error codes.

Returns

array —

List of error codes, if available.

getErrorCode()

getErrorCode() : string|integer

Retrieve first error code available.

Returns

string|integer —

Empty string, if no error codes.

getErrorMessages()

getErrorMessages(string|integer  $code = '') : array

Retrieve all error messages or error messages matching code.

Parameters

string|integer $code

Optional. Retrieve messages matching code, if exists.

Returns

array —

Error strings on success, or empty array on failure (if using code parameter).

getErrorMessage()

getErrorMessage(string|integer  $code = '') : string

Get single error message.

This will get the first message available for the code. If no code is given then the first code available will be used.

Parameters

string|integer $code

Optional. Error code to retrieve message.

Returns

string

getErrorData()

getErrorData(string|integer  $code = '') : mixed

Retrieve error data for error code.

Parameters

string|integer $code

Optional. Error code.

Returns

mixed —

Error data, if it exists.

add()

add(string|integer  $code, string  $message, mixed  $data = '') 

Add an error or append additional message to an existing error.

Parameters

string|integer $code

Error code.

string $message

Error message.

mixed $data

Optional. Error data.

addData()

addData(mixed  $data, string|integer  $code = '') 

Add data for error code.

The error code can only contain one error data.

Parameters

mixed $data

Error data.

string|integer $code

Error code.

remove()

remove(string|integer  $code) 

Removes the specified error.

This function removes all error messages associated with the specified error code, along with any error data for that code.

Parameters

string|integer $code

Error code.