Download the PHP package rollerworks/exception-parser without Composer
On this page you can find all versions of the php package rollerworks/exception-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rollerworks/exception-parser
More information about rollerworks/exception-parser
Files in rollerworks/exception-parser
Package exception-parser
Short Description Extracts exception-information to an array
License MIT
Informations about the package exception-parser
RollerworksExceptionParser
This package provides the Rollerworks ExceptionParser which extracts exception-data to an array.
Basically it wraps multiple exception-catch blocks into one call, and returns the parsed information.
Installation
1. Using Composer
To install the Rollerworks ExceptionParser, add rollerworks/exception-parser
to your composer.json
Or manually, by adding the following to your
composer.json
file:
Then, you can install the new dependency by running Composer's update
command from the directory where your composer.json
file is located:
Note: This package is stand-alone, composer is only used for generating the autoloader class.
You can also use your own autoloader, but make sure its PSR-4 compatible. See the composer.json file in this package for mapping information.
Usage
Usage is very simple, each exception that you want to process needs a compatible parser which parses the Exception to an array.
The ExceptionParserManager passes trough all the registered exception-parses in order of registration, till one accepts the exception.
When no compatible parser is found an empty array is returned instead.
Exception class
Exception Parser
The SearchFieldRequiredExceptionParser
exception parser
parses the FieldRequiredException
shown above.
ParserManager
Now register the Parser at the ExceptionParserManager.
Note: You can register as many processors as needed.
Key transforming
The ExceptionParserManager also allows to transform the array-key to another format like '{{ name }}'.
'{var}' is the placeholder which is replaced by the current key.
Or you can use a callback that returns the transformed key. This is very useful if the keys contains a prefix or is wrapped inside a special format.
Note: If the callback returns null or void the key is added as incrementing index. Only when the "callback" returns null or void, setting null as constructor value is the default and will not transform the array-keys.