diff --git a/src/AwakiContext.php b/src/AwakiContext.php index 16b4d93..c54848c 100644 --- a/src/AwakiContext.php +++ b/src/AwakiContext.php @@ -55,6 +55,6 @@ class AwakiContext { } private function registerHttpRoutes(): void { - new RedirectorRoutes($this->router, $this->dbConn, $this->urls); + $this->router->register(new RedirectorRoutes($this->dbConn, $this->urls)); } } diff --git a/src/RedirectorRoutes.php b/src/RedirectorRoutes.php index 586f416..9db2f44 100644 --- a/src/RedirectorRoutes.php +++ b/src/RedirectorRoutes.php @@ -2,40 +2,27 @@ namespace Awaki; use Index\Data\IDbConnection; -use Index\Http\Routing\IRouter; +use Index\Http\Routing\{HandlerAttribute,HttpGet,IRouter,IRouteHandler}; use Index\Serialisation\Base62; use Syokuhou\IConfig; -final class RedirectorRoutes { +final class RedirectorRoutes implements IRouteHandler { private IDbConnection $dbConn; private IConfig $urls; - public function __construct(IRouter $router, IDbConnection $dbConn, IConfig $urls) { + public function __construct(IDbConnection $dbConn, IConfig $urls) { $this->dbConn = $dbConn; $this->urls = $urls; + } - $router->get('/', $this->index(...)); - - // profile - $router->get('/[up]([0-9]+)', $this->redirectProfile(...)); - $router->get('/[up]/([A-Za-z0-9\-_]+)', $this->redirectProfile(...)); - - // satori short urls - $router->get('/[bg]/([A-Za-z0-9]+)', $this->redirectSatoriShort(...)); - - // forum categories - $router->get('/fc?/?([0-9]+)', $this->redirectForumCategory(...)); - - // forum topic - $router->get('/ft/?([0-9]+)', $this->redirectForumTopic(...)); - - // forum post - $router->get('/fp/?([0-9]+)', $this->redirectForumPost(...)); + public function registerRoutes(IRouter $router): void { + HandlerAttribute::register($router, $this); // databased, registered last cuz it matches everything otherwise! $router->get('/([A-Za-z0-9\-_]+)', $this->redirectDatabase(...)); } + #[HttpGet('/')] public function index($response): void { $response->accelRedirect('/index.html'); $response->setTypeHTML(); @@ -66,6 +53,7 @@ final class RedirectorRoutes { $this->redirect($response, $request, $info->getString(1)); } + #[HttpGet('/[bg]/([A-Za-z0-9]+)')] public function redirectSatoriShort($response, $request, string $linkId) { $linkId = Base62::decode($linkId); @@ -88,18 +76,23 @@ final class RedirectorRoutes { $this->redirect($response, $request, $url); } + #[HttpGet('/[up]([0-9]+)')] + #[HttpGet('/[up]/([A-Za-z0-9\-_]+)')] public function redirectProfile($response, $request, string $userId) { $this->redirectSimple($response, $request, $this->urls->getString('user_profile'), $userId); } + #[HttpGet('/fc?/?([0-9]+)')] public function redirectForumCategory($response, $request, string $categoryId) { $this->redirectSimple($response, $request, $this->urls->getString('forum_category'), $categoryId); } + #[HttpGet('/ft/?([0-9]+)')] public function redirectForumTopic($response, $request, string $topicId) { $this->redirectSimple($response, $request, $this->urls->getString('forum_topic'), $topicId); } + #[HttpGet('/fp/?([0-9]+)')] public function redirectForumPost($response, $request, string $postId) { $this->redirectSimple($response, $request, $this->urls->getString('forum_post'), $postId); }