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(
)
:
stringGrabs formatted validation messages for all objects in the validation queue.
| Type | Description |
|---|---|
| string | The compiled validation message returned. |
- Access
- protected

addError(
string | array $msg
)
:
voidAdd 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
)
:
voidAdd 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
)
:
voidAdds an object to the validation queue.
| Name | Type | Description |
|---|---|---|
| $obj | \xPDOObject | An xPDOObject to validate. |
- Access
- public

checkValidation(
\xPDOObject | array $objs
=
array()
)
:
stringChecks 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 | arraySend 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
)
:
arrayReturn 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(
)
:
arrayReturn the fields added as errors.
| Type | Description |
|---|---|
| array | An array of errors for specific fields. |

hasError(
)
:
booleanCheck 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
)
:
booleanReturns 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
)
:
booleanReturns 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 | arrayProcess 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 | arraySend 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
)
:
arrayConverts 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). |