Whoops

PSR-15 Whoops error handler middleware for BitFrame microframework

Releases

{
    "require": {
		"designcise/bitframe-whoops": "^1.0.0"
	}
}

Install

Add the following as a dependency in your project's composer.json:

"designcise/bitframe-whoops": "^1.0.0"

Getting Started →

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  */
$handler = new WhoopsErrorHandler($format, $handleGlobalErrors, $showTrace);
$app->run([
    /* \BitFrame\Message\DiactorosResponseEmitter::class, */
    $handler
]);

Getting Started

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

  1. format (callable|string, optional): (default: auto) The following options: auto, text, html, json, xml or custom function.
  2. handleGlobalErrors (bool, optional) : (default: false) If false, errors are handled only within the middleware chain for all the middlewares that appear after.
  3. showTrace (bool, optional) : (default: false) If true, full stack trace of error is shown.

← Install Output Format →

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([
    /* \BitFrame\Message\DiactorosResponseEmitter::class, */
    $handler
]);

Output Format

  • 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.

← Getting Started Handling Errors →

use \BitFrame\ErrorHandler\WhoopsErrorHandler;

require 'vendor/autoload.php';

$app = new \BitFrame\Application;

$format = 'auto';
$handleGlobalErrors = false;true;
$handler = new WhoopsErrorHandler($format, $handleGlobalErrors);

$app->run([
    /* \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

Handling Errors

  1. false: Errors are handled only within the middleware chain for all the middlewares that appear after.
  2. true: Errors are handled globally that appear after the whoops error handler has been processed by the middleware dispatcher.

← Output Format Show Error Trace →

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([
    /* \BitFrame\Message\DiactorosResponseEmitter::class, */
    $handler
]);
								

Show Error Trace

  1. false: Error trace is not shown.
  2. true: Error trace is shown (if available via the selected format).

← Handling Errors About →

/**
 * Whoops Error Handler Wrapper (PSR-15 / PSR-7 compatible)
 *
 * @author    
 * @copyright Copyright (c) 2017-2018 Daniyal Hamid (https://designcise.com)
 *
 * @license   MIT License
 */

About

Whoops error handler helps manage and prettify php errors and exceptions in PHP.

Whoops Official GitHub

← Show Error Trace API →

Comments

Let us know if you have something to say or add

Changelog

Latest version 1.0.0 released on Feb 14, 2018

Version 1.0.1

  • Added support for JSONP requests
  • Created a JSONP handler for Whoops

Version 1.0.0

  • Format negotiater to get the preferred format based on the Accept header
  • PSR-15 & PSR-7 Support
  • Support to specify output format
  • Support to show/hide stack trace
  • Support to limit error handling to middleware chain only instead of global error checking