mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
b07348a3df
- Removed temporary `RouterException` class. - Added object-types to parameters in `CallbackExceptionHandler` and `SimpleRouter` classes. - Router now renders groups even if callback is null. - Renamed `setMiddleware` to `addMiddleware` in `Route` class and `IRoute` interface. - `addMiddleware` now accept both object and class strings in `Route` class. - `addExceptionHandler` now accept both object and class strings in `RouteGroup` class. - Added unit-test for rewrite-exception message change: `testRewriteExceptionMessage` in `RouterRewriteTest`. - Fixed typo: renamed `testSimularUrls` to `testSimilarUrls` in `RouterUrlTest`.
38 lines
823 B
PHP
38 lines
823 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
|
|
* @return Request|null
|
|
*/
|
|
public function handleError(Request $request, \Exception $error)
|
|
{
|
|
/* Fire exceptions */
|
|
return call_user_func($this->callback,
|
|
$request,
|
|
$error
|
|
);
|
|
}
|
|
} |