2023-10-06 21:11:28 +00:00
|
|
|
<?php
|
|
|
|
namespace Seria;
|
|
|
|
|
2024-03-30 00:38:44 +00:00
|
|
|
use Index\Http\Routing\{HttpRouter,IRouter,IRouteHandler};
|
2023-10-06 21:11:28 +00:00
|
|
|
|
|
|
|
class RoutingContext {
|
2024-03-30 00:38:44 +00:00
|
|
|
private HttpRouter $router;
|
2023-10-06 21:11:28 +00:00
|
|
|
|
2024-03-30 00:38:44 +00:00
|
|
|
public function __construct(SeriaContext $context) {
|
|
|
|
$this->router = new HttpRouter(errorHandler: new RoutingErrorHandler($context));
|
2023-10-06 21:11:28 +00:00
|
|
|
$this->router->use('/', fn($resp) => $resp->setPoweredBy('Seria'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRouter(): IRouter {
|
|
|
|
return $this->router;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function register(IRouteHandler $handler): void {
|
|
|
|
$this->router->register($handler);
|
|
|
|
}
|
|
|
|
|
2024-03-30 00:38:44 +00:00
|
|
|
public function dispatch(): void {
|
|
|
|
$this->router->dispatch();
|
2023-10-06 21:11:28 +00:00
|
|
|
}
|
|
|
|
}
|