{ "require": { "designcise/bitframe-whoops": "^1.0.0" } }
Add the following as a dependency in your project's composer.json
:
"designcise/bitframe-whoops": "^1.0.0"
use \BitFrame\ErrorHandler\WhoopsErrorHandler; require 'vendor/autoload.php'; $app = new \BitFrame\Application; // instantiation with default options $handler = new WhoopsErrorHandler;// lazy instantiation with default options $handler = WhoopsErrorHandler::class;/* instantiate with custom options * * @param callable|string $format * @param bool $handleGlobalErrors * @param bool $showTrace * * To create a custom error handler function you can specify output format * as a callable, for example: * * $format = function($exception, $inspector, $error_handler) { * // @see https://github.com/filp/whoops/wiki/API-Documentation * echo $exception->getCode() . ' ' . $exception->getMessage(); * return \Whoops\Handler\Handler::QUIT; * }; */ $handler = new WhoopsErrorHandler($format, $handleGlobalErrors, $showTrace); $app->run([ /* In order to output response from the whoops error handler, * make sure you include a response emitter middleware, for example: * \BitFrame\Message\DiactorosResponseEmitter::class, */ $handler ]);
You can create a new instance of \BitFrame\ErrorHandler\WhoopsErrorHandler
simply by using the new
keyword.
You can also do lazy instantiation, if it's supported by your middleware dispatcher, by just providing the class name with its namespace, or simply by appending ::class
to an object instance or class name.
You won't be able to call any methods on the object with lazy instantiation as it's a mere string representation of the namespaced class name which is converted to an object instance at runtime.
You can specify the following three arguments when creating a new instance of the object
auto
, text
, html
, json
, xml
or custom function.false
, errors are handled only within the middleware chain for all the middlewares that appear after.true
, full stack trace of error is shown.use \BitFrame\ErrorHandler\WhoopsErrorHandler; require 'vendor/autoload.php'; $app = new \BitFrame\Application; $format = 'auto';// or 'txt' or 'plain' $format = 'text';$format = 'html';$format = 'json';$format = 'xml';$format = function($exception, $inspector, $error_handler) { // @see https://github.com/filp/whoops/wiki/API-Documentation echo $exception->getCode() . ' ' . $exception->getMessage(); return \Whoops\Handler\Handler::QUIT; }; $handler = new WhoopsErrorHandler($format); $app->run([ /* In order to output response from the whoops error handler, * make sure you include a response emitter middleware, for example: * \BitFrame\Message\DiactorosResponseEmitter::class, */ $handler ]);
auto
: This is the default format for error handling; when set, the most suitable error output format is selected automatically.text
: Output in plain text.html
: Output in html.json
: Output as json.xml
: Output in xml.callable
: Custom output function.use \BitFrame\ErrorHandler\WhoopsErrorHandler; require 'vendor/autoload.php'; $app = new \BitFrame\Application; $format = 'auto'; $handleGlobalErrors = false;true; $handler = new WhoopsErrorHandler($format, $handleGlobalErrors); $app->run([ /* In order to output response from the whoops error handler, * make sure you include a response emitter middleware, for example: * \BitFrame\Message\DiactorosResponseEmitter::class, */ $handler,
// handle errors occuring here-on only within the middleware chain function($request, $response, $next) {Whatever::css;return $next($request, $response); }]); // any error occuring here-on will be handled
false
: Errors are handled only within the middleware chain for all the middlewares that appear after.true
: Errors are handled globally that appear after the whoops error handler has been processed by the middleware dispatcher.use \BitFrame\ErrorHandler\WhoopsErrorHandler; require 'vendor/autoload.php'; $app = new \BitFrame\Application; $format = 'auto'; $handleGlobalErrors = false; $showTrace = false;true; $handler = new WhoopsErrorHandler($format, $handleGlobalErrors, $showTrace); $app->run([ /* In order to output response from the whoops error handler, * make sure you include a response emitter middleware, for example: * \BitFrame\Message\DiactorosResponseEmitter::class, */ $handler ]);
false
: Error trace is not shown.true
: Error trace is shown (if available via the selected format)./** * Whoops Error Handler Wrapper (PSR-15 / PSR-7 compatible) * * @author Daniyal Hamid * @copyright Copyright (c) 2017-2018 Daniyal Hamid (https://designcise.com) * * @license MIT License */
Whoops error handler helps manage and prettify php errors and exceptions in PHP.
Whoops Official GitHubLet us know if you have something to say or add
Latest version 1.0.0 released on Feb 14, 2018