Files
simple-php-router/src/Pecee/SimpleRouter/Handlers/CallbackExceptionHandler.php
T
Simon Sessingø b3c135c723 Development
- Fixed DebugHandler::fireEvent not providing correct arguments when calling fireEvents.
- Fixed custom regex setMatch not setting parsed parameters correctly (issue: #566).
- Added unit-tests for catching issue in the future.
- Added php-stan typehints.
2021-06-15 10:11:09 +02:00

42 lines
882 B
PHP

<?php
namespace Pecee\SimpleRouter\Handlers;
use Closure;
use Exception;
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\SimpleRouter\Handlers
*/
class CallbackExceptionHandler implements IExceptionHandler
{
/**
* @var Closure
*/
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
);
}
}