zoopcommerce / maggott-module
Zend Framework 2 Module that provides exception handling functionality
Installs: 1 194
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=5.4
- zendframework/zendframework: ~2.2
Requires (Dev)
- phpunit/phpunit: >=3.7
- squizlabs/php_codesniffer: 1.4.*
This package is not auto-updated.
Last update: 2024-12-17 06:48:59 UTC
README
A simple zend framework 2 module to return exceptions as json in accordance with the application/api-problem+json standard.
Install
Add the following to your composer root:
"require": {
"zoopcommerce/maggott-module" : "~1.1"
}
Add the module to your application config:
'modules' => [
'Zoop\MaggottModule'
],
Configuration
Any exceptions that you want returned as json need to be configured in the exception_map
config key.
Eg:
'zoop' => [
'maggott' => [
'exception_map' => [
'Zoop\ShardModule\Exception\AccessControlException' => [
'described_by' => 'access-control-exception',
'title' => 'Access denied',
'status_code' => 403,
'extra_fields' => ['action'],
'restricted_extra_fields' => ['documentClass']
]
]
],
]
The exception_map
is an array of configured exceptions. The key for each item in the array must be the FQCN of the exception. All fields to configure an exception are optional. They are:
described_by
If this field is supplied, the returned exception will have a described_by
field which points to a resource where more information about the exception can be found in human readable format.
If using the described_by
field, you should also create a view model template called zoop/maggott/<described_by>
that hold the extra human readable inforamtion.
title
The title of the exception
status_code
The http status code should the json response be set to. Defaults to 500, but also observes the status code in the response.
extra_fields
Other properties of the exception that should always be included in the json response.
restricted_extra_fields
Other properties of the exception that should only be included in the json response if displayExceptions
is set to true
.