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 40 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 ( )

Get the error code.

Returns
String

Definition at line 78 of file ApplicationError.php.

getLevel ( )

Get the error level.

Returns
String

Definition at line 86 of file ApplicationError.php.

getStatusCode ( )

Get the associated HTTP status code.

Returns
Integer

Definition at line 94 of file ApplicationError.php.

getMessage ( )

Get the error message.

Returns
String

Definition at line 102 of file ApplicationError.php.

setData (   $data)

Set the error data.

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

Definition at line 111 of file ApplicationError.php.

getData ( )

Get the error data.

Returns
Mixed

Definition at line 119 of file ApplicationError.php.

__toString ( )

Get a string representation of the error.

Returns
String

Definition at line 127 of file ApplicationError.php.

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 143 of file ApplicationError.php.

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 161 of file ApplicationError.php.

static fromException ( \Exception  $ex)
static

Factory method for transforming an exception into an ApplicationError instance.

Parameters
$exException
Returns
ApplicationError

Definition at line 171 of file ApplicationError.php.

Member Data Documentation

const LEVEL_WARNING = 'warning'

Definition at line 43 of file ApplicationError.php.

const LEVEL_ERROR = 'error'

Definition at line 44 of file ApplicationError.php.

const LEVEL_FATAL = 'fatal'

Definition at line 45 of file ApplicationError.php.

const DEFAULT_ERROR_STATUS = 500

Definition at line 47 of file ApplicationError.php.