mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
37 lines
795 B
PHP
37 lines
795 B
PHP
<?php
|
|
|
|
namespace Pecee\Handlers;
|
|
|
|
use Pecee\Http\Request;
|
|
|
|
/**
|
|
* Class CallbackExceptionHandler
|
|
*
|
|
* Class is used to create callbacks which are fired when an exception is reached.
|
|
* This allows for easy handling 404-exception etc. without creating an custom ExceptionHandler.
|
|
*
|
|
* @package Pecee\Handlers
|
|
*/
|
|
class CallbackExceptionHandler implements IExceptionHandler
|
|
{
|
|
|
|
protected $callback;
|
|
|
|
public function __construct(\Closure $callback)
|
|
{
|
|
$this->callback = $callback;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @param \Exception $error
|
|
*/
|
|
public function handleError(Request $request, \Exception $error): void
|
|
{
|
|
/* Fire exceptions */
|
|
\call_user_func($this->callback,
|
|
$request,
|
|
$error
|
|
);
|
|
}
|
|
} |