33 lines
957 B
PHP
33 lines
957 B
PHP
<?php
|
|
namespace Seria;
|
|
|
|
use Index\Http\{HttpResponseBuilder,HttpRequest};
|
|
use Index\Http\ErrorHandling\IErrorHandler;
|
|
|
|
class RoutingErrorHandler implements IErrorHandler {
|
|
public function __construct(
|
|
private SeriaContext $context
|
|
) {}
|
|
|
|
public function handle(HttpResponseBuilder $response, HttpRequest $request, int $code, string $message): void {
|
|
if($code === 500) {
|
|
$response->setTypeHTML();
|
|
$response->setContent(file_get_contents(SERIA_DIR_TEMPLATES . '/500.html'));
|
|
return;
|
|
}
|
|
|
|
$templating = $this->context->getTemplating();
|
|
if($templating === null) {
|
|
$response->setTypePlain();
|
|
$response->setContent((string)$code);
|
|
return;
|
|
}
|
|
|
|
$response->setTypeHTML();
|
|
$response->setContent($templating->render('http-error', [
|
|
'http_code' => $code,
|
|
'http_text' => $message,
|
|
]));
|
|
}
|
|
}
|