My attempt to remake the (Whoops) ExceptionHandler
.
These changes have a huge impact on performance. (less reponse time)
But it's still work in progress, I have a proposal that may affect the final result.
I used the Whoops handlers as a formatters, which are used a generic Responder like FormattedResponder
and DTO Payload
. That seems the obvious way, and does not violate the ADR pattern:
Action-Domain-Responder: View vs Responder
Note also that a generic Responder may be used by more than one Action.
The point is that the Action leaves all header and content work to the Responder, not that there must be a different Responder for each different View.
My suggestions
To make an interfaces for exceptions, it's a sketch:
use Equip\Exception\ExceptionInterface;
interface EquipExceptionHandlerInterface
{
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next
);
public function withEquipException(ExceptionInterface $exception);
}
use Exception;
interface ExceptionHandlerInterface
{
public function withException(Exception $exception);
}
use Throwable;
interface ThrowableHandlerInterface
{
public function withThrowable(Throwable $throwable);
}
Use a PSR logger as a decorator. Soon I'll add it.
Use the Whoops as a separate package. It already looks like that.
Use for the Equip a simple (native) exception handler by default, and change it using a DI.
use Equip\Exception\ExceptionInterface;
use Exception;
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next
) {
try {
return $next($request, $response);
} catch (ExceptionInterface $exception) {
return $this->exceptionHandler->withEquipException($request, $response, $exception);
} catch (Exception $exception) {
return $this->exceptionHandler->withException($request, $response, $exception);
}
}