This repository has been archived on 2024-08-28. You can view files and clone it, but cannot push or open issues or pull requests.
satori-services/src/RoutingContext.php

37 lines
1.3 KiB
PHP
Raw Normal View History

2023-11-06 00:45:15 +00:00
<?php
namespace Satori;
use Index\Http\HttpFx;
use Index\Http\HttpRequest;
use Index\Routing\IRouter;
use Index\Routing\IRouteHandler;
class RoutingContext {
private HttpFx $router;
public function __construct() {
$this->router = new HttpFx;
$this->router->use('/', fn($resp) => $resp->setPoweredBy('Satori'));
}
public function getRouter(): IRouter {
return $this->router;
}
public function registerDefaultErrorPages(): void {
$this->router->addErrorHandler(401, fn($resp) => $resp->setContent(file_get_contents(SAT_DIR_PUBLIC . '/404.html')));
$this->router->addErrorHandler(403, fn($resp) => $resp->setContent(file_get_contents(SAT_DIR_PUBLIC . '/404.html')));
$this->router->addErrorHandler(404, fn($resp) => $resp->setContent(file_get_contents(SAT_DIR_PUBLIC . '/404.html')));
$this->router->addErrorHandler(500, fn($resp) => $resp->setContent(file_get_contents(SAT_DIR_PUBLIC . '/404.html')));
$this->router->addErrorHandler(503, fn($resp) => $resp->setContent(file_get_contents(SAT_DIR_PUBLIC . '/404.html')));
}
public function register(IRouteHandler $handler): void {
$this->router->register($handler);
}
public function dispatch(?HttpRequest $request = null): void {
$this->router->dispatch($request);
}
}