API

Overview of the bitframe-whoops package including classes and their methods and properties

View Source

namespace BitFrame\ErrorHandler;

use \Psr\Http\Message\ServerRequestInterface;

/**
 * Detect any of the supported preferred formats 
 * from an HTTP request.
 */
class FormatNegotiator
{
    /** @var array  */
    private static $formats = [  ];

    /**
     * Returns the preferred format based on 
     * the Accept header.
     *
     * @param ServerRequestInterface $request
     * @return string
     */
    public static function getPreferredFormat(  ): string;
}
namespace BitFrame\ErrorHandler;

use \Psr\Http\Message\ServerRequestInterface;
use \Psr\Http\Message\ResponseInterface;
use \Psr\Http\Server\RequestHandlerInterface;
use \Whoops\Run;
use \Whoops\Handler\PlainTextHandler;
use \Whoops\Handler\JsonResponseHandler;
use \Whoops\Handler\XmlResponseHandler;
use \Whoops\Handler\PrettyPageHandler;

// implements:
use \Psr\Http\Server\MiddlewareInterface;

// uses:
use \BitFrame\Delegate\CallableMiddlewareTrait;

// exceptions:
use \TypeError;
use \UnexpectedValueException;

/**
 * Whoops error handler middleware to handle application
 * or middleware specific errors.
 */
class WhoopsErrorHandler implements MiddlewareInterface
{
    use CallableMiddlewareTrait;
    
    /** @var callable|string */
    private $outputFormat;
    
    /** @var bool */
    private $handleGlobalErrors;
    
    /** @var bool */
    private $showTrace;
    
    /**
     * @param callable|string $outputFormat (optional, default: 'auto')
     * @param bool $handleGlobalErrors (optional, default: false)
     * @param bool $showTrace (optional, default: false)
     */
    public function __construct(  );
    
    /**
     * Process an incoming server request and return a
     * response, optionally delegating response creation
     * to a handler.
     *
     * @param ServerRequestInterface $request
     * @param RequestHandlerInterface $handler
     *
     * @return ResponseInterface
     *
     * @throws TypeError
     * @throws UnexpectedValueException
     */
    public function process(  ): ResponseInterface;
    
    /**
     * Get Whoops object instance.
     *
     * @param ServerRequestInterface $request
     * @param string|callable $format (optional, default: 'auto')
     * @param bool $showTrace (optional, default: false)
     *
     * @return \Whoops\Run
     */
    public static function getWhoopsInstance(  ): Run;
    
    /**
     * Handle caught exceptions/throwables.
     *
     * @param Exception|Throwable $error
     * @param ServerRequestInterface $request
     *
     * @return ResponseInterface
     */
    private function handleThrowable(  ): ResponseInterface;
    
    /**
     * Creates and returns a callable error 
     * handler that raises exceptions. 
     *
     * @return callable
     */
    private function createErrorHandler(  ): callable;
}
namespace BitFrame\ErrorHandler\Handler;

use \Whoops\Exception\Formatter;

// extends:
use \Whoops\Handler\Handler;

/**
 * Catches an exception and converts it to a JSONP
 * response. Additionally can also return exception
 * frames for consumption by an API. Based on
 * \Whoops\Handler\JsonResponseHandler.
 */
class JsonpResponseHandler extends Handler
{
    /** @var bool */
    private $returnFrames = false;

    /** @var bool */
    private $jsonApi = false;
    
    /** @var string */
    private $callback;

    /**
     * @param string $callback JSONP callback
     */
    public function __construct(  );

    /**
     * Returns errors[[]] instead of error[] to be in 
     * compliance with the json:api spec.
     *
     * @param bool $jsonApi (optional, default: false)
     *
     * @return $this
     */
    public function setJsonApi(  ): self;

    /**
     * @param bool|null $returnFrames
     *
     * @return bool|$this
     */
    public function addTraceToOutput(  );

    /**
     * Handle errors.
     *
     * @return int
     */
    public function handle(): int;

    /**
     * Get content type.
     * 
     * @return string
     */
    public function contentType(): string;
}

Comments

Let us know if you have something to say or add