hanyuu/src/RoutingContext.php

29 lines
765 B
PHP

<?php
namespace Hanyuu;
use Index\Http\Routing\{HttpRouter,IRouter,IRouteHandler};
use Sasae\SasaeEnvironment;
class RoutingContext {
private HttpRouter $router;
private SasaeEnvironment $templating;
public function __construct(SasaeEnvironment $templating) {
$this->templating = $templating;
$this->router = new HttpRouter(errorHandler: new RoutingErrorHandler($templating));
$this->router->use('/', fn($resp) => $resp->setPoweredBy('Hanyuu'));
}
public function getRouter(): IRouter {
return $this->router;
}
public function register(IRouteHandler $handler): void {
$this->router->register($handler);
}
public function dispatch(): void {
$this->router->dispatch();
}
}