fivelab / error
Control error codes with many systems
Installs: 1 118
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2017-08-16 12:51:51 UTC
README
With this package, you can control error codes and exceptions in system with many sub systems.
Installation
Add FiveLab/Error in your composer.json:
{ "require": { "fivelab/error": "~1.0" } }
Now tell composer to download the library by running the command:
$ php composer.phar update fivelab/error
Basic usage
For collect all error codes, you must create a error factory in you sub system:
use FiveLab\Component\Error\ErrorFactoryInterface; final class MySystemError implements ErrorFactoryInterface { const ERROR_1 = 1; const ERROR_2 = 2; public function getErrors() { return [ self::ERROR_1 => 'Error #1', self::ERROR_2 => 'Error #2' ]; } public function getExceptions() { return []; } public function getReservedDiapason() { return [1, 5]; } }
And create error system (Storage), and add this factory to storage:
use FiveLab\Component\Error\Errors; $errors = new Errors(); $errors->addFactory(new MySystemError());
After, you can:
- Get reserved diapasons for each system
$errors->getReservedCodes();
- Get all errors for system
$errors->getErrors();
- Get all exceptions
$exceptions = $errors->getExceptions();
- Check, if has exception in errors storage
$exception = new \Exception(); $errors->hasException($exception);
- Get error code for exception
$exception = new \Exception(); $code = $errors->getExceptionCode($exception);
- Check reserved codes
$errors->checkReservedCodes();