Detailed Description

ApplicationError is used to signal errors that occur while processing a request.

This class allows to use predefined errors by using the ApplicationError::get() method. Errors are defined in the following way:

$message = ObjectFactory::getInstance('message');
define('GENERAL_ERROR', serialize(['GENERAL_ERROR', ApplicationError::LEVEL_ERROR, 400,
$message->getText('An unspecified error occurred.')
]));

To use the error in the code:

$error = ApplicationError::get('GENERAL_ERROR', $mySpecificErrorData);
Author
ingo herwig ingo@.nosp@m.wemo.nosp@m.ve.co.nosp@m.m

Definition at line 41 of file ApplicationError.php.

Public Member Functions

 getCode ()
 
 getLevel ()
 
 getStatusCode ()
 
 getMessage ()
 
 setData ($data)
 
 getData ()
 
 __toString ()
 

Static Public Member Functions

static get ($code, $data=null)
 
static getGeneral ($message, $statusCode=self::DEFAULT_ERROR_STATUS)
 
static fromException (\Exception $ex)
 

Public Attributes

const LEVEL_WARNING = 'warning'
 
const LEVEL_ERROR = 'error'
 
const LEVEL_FATAL = 'fatal'
 
const DEFAULT_ERROR_STATUS = 500
 

Member Function Documentation

◆ getCode()

getCode ( )

Get the error code.

Returns
String

Definition at line 79 of file ApplicationError.php.

◆ getLevel()

getLevel ( )

Get the error level.

Returns
String

Definition at line 87 of file ApplicationError.php.

◆ getStatusCode()

getStatusCode ( )

Get the associated HTTP status code.

Returns
Integer

Definition at line 95 of file ApplicationError.php.

◆ getMessage()

getMessage ( )

Get the error message.

Returns
String

Definition at line 103 of file ApplicationError.php.

◆ setData()

setData (   $data)

Set the error data.

Parameters
$dataSome error codes require to transmit further information to the client

Definition at line 112 of file ApplicationError.php.

◆ getData()

getData ( )

Get the error data.

Returns
Mixed

Definition at line 120 of file ApplicationError.php.

◆ __toString()

__toString ( )

Get a string representation of the error.

Returns
String

Definition at line 128 of file ApplicationError.php.

◆ get()

static get (   $code,
  $data = null 
)
static

Factory method for retrieving a predefined error instance.

Parameters
$codeAn error code
$dataSome error codes required to transmit further information to the client (optional, default: null)
Returns
ApplicationError

Definition at line 144 of file ApplicationError.php.

◆ getGeneral()

static getGeneral (   $message,
  $statusCode = self::DEFAULT_ERROR_STATUS 
)
static

Factory method for creating a general error instance.

Parameters
$messageError message
$statusCodeHTTP status code (optional, default: DEFAULT_ERROR_STATUS)
Returns
ApplicationError

Definition at line 162 of file ApplicationError.php.

◆ fromException()

static fromException ( \Exception  $ex)
static

Factory method for transforming an exception into an ApplicationError instance.

Parameters
$exException
Returns
ApplicationError

Definition at line 172 of file ApplicationError.php.

Member Data Documentation

◆ LEVEL_WARNING

const LEVEL_WARNING = 'warning'

Definition at line 44 of file ApplicationError.php.

◆ LEVEL_ERROR

const LEVEL_ERROR = 'error'

Definition at line 45 of file ApplicationError.php.

◆ LEVEL_FATAL

const LEVEL_FATAL = 'fatal'

Definition at line 46 of file ApplicationError.php.

◆ DEFAULT_ERROR_STATUS

const DEFAULT_ERROR_STATUS = 500

Definition at line 48 of file ApplicationError.php.

static get($code, $data=null)
Factory method for retrieving a predefined error instance.
static getInstance($name, $dynamicConfiguration=[])