core/model/modx/error/moderror.class.php
Error handler for request/response processing.
- Package
- modx
- Subpackage
- error
\modError
Abstract class for error handling and validation for requests.
- Abstract
- Implement a derivative of this class for error handling and validation of any kind of MODX request.
Properties


array
$_objects= 'array()'
array()
Details- Type
- array
Methods


__construct(
\modX $modx, string $message
=
''
)
:
void
Name | Type | Description |
---|---|---|
$modx | \modX | A reference to the modX instance |
$message | string | The default message to send as an error response |


_validate(
)
:
string
Grabs formatted validation messages for all objects in the validation queue.
Type | Description |
---|---|
string | The compiled validation message returned. |
- Access
- protected


addError(
string | array $msg
)
:
void
Add an error to the error queue.
Name | Type | Description |
---|---|---|
$msg | string | array | An error message string or custom error array. |


addField(
string $name, string $error
)
:
void
Add a specific field error to the error queue.
Name | Type | Description |
---|---|---|
$name | string | The id of the field. |
$error | string | The error message. |


addObjectToValidate(
\xPDOObject $obj
)
:
void
Adds an object to the validation queue.
Name | Type | Description |
---|---|---|
$obj | \xPDOObject | An xPDOObject to validate. |
- Access
- public


checkValidation(
\xPDOObject | array $objs
=
array()
)
:
string
Checks validation, and if any errors are found, returns them. Error handlers that derive from this can determine their own behaviour should errors be found.
Name | Type | Description |
---|---|---|
$objs | \xPDOObject | array | An xPDOObject or array of xPDOObjects to add to the validation queue. |
Type | Description |
---|---|
string | The validation message returned. |
- Access
- public


failure(
string $message
=
'', object | array | string $object
=
null
)
:
string | array
Send a failure error message.
Name | Type | Description |
---|---|---|
$message | string | The error message to send. |
$object | object | array | string | An object to send back to the output. |
Type | Description |
---|---|
string | array | The failure response |


getErrors(
boolean $includeFields
=
false
)
:
array
Return all of the errors in the error queue.
Name | Type | Description |
---|---|---|
$includeFields | boolean | Whether or not to include the fields in the error response |
Type | Description |
---|---|
array | An array of errors |


getFields(
)
:
array
Return the fields added as errors.
Type | Description |
---|---|
array | An array of errors for specific fields. |


hasError(
)
:
boolean
Check to see if there is any errors on the queue.
Type | Description |
---|---|
boolean | True if there are errors or a message has been specified. |


isFieldError(
mixed $error
)
:
boolean
Returns true if the error passed to it represents a field error.
Name | Type | Description |
---|---|---|
$error | mixed | An element of modError::errors. |
Type | Description |
---|---|
boolean | True if the error is a field error. |


isNotFieldError(
mixed $error
)
:
boolean
Returns true if the error passed to it does not represent a field error.
Name | Type | Description |
---|---|---|
$error | mixed | An element of modError::errors. |
Type | Description |
---|---|
boolean | True if the error is not a field error. |


process(
string $message
=
'', boolean $status
=
false, object | array $object
=
null
)
:
string | object | array
Process errors and return a proper output value.
Name | Type | Description |
---|---|---|
$message | string | The error message to output. |
$status | boolean | Whether or not the action is a success or failure. |
$object | object | array | The object to send back to output. |
Type | Description |
---|---|
string | object | array | The transformed object data array. |


success(
string $message
=
'', object | array | string $object
=
null
)
:
string | array
Send a success error message.
Name | Type | Description |
---|---|---|
$message | string | The error message to send. |
$object | object | array | string | An object to send back to the output. |
Type | Description |
---|---|
string | array | The success response |


toArray(
array | \xPDOObject | object $object
)
:
array
Converts an object or objects embedded in an array, to arrays.
This function also makes sure that any members of the array are not PHP resource types (e.g. database connections, file handles, etc.).
Name | Type | Description |
---|---|---|
$object | array | \xPDOObject | object | An array or object to process. |
Type | Description |
---|---|
array | Returns an array representation of the object(s). |