From 07105970622c9e1ac4f48dfa05601b1f94e897be Mon Sep 17 00:00:00 2001 From: flashwave Date: Thu, 7 Sep 2023 22:22:41 +0000 Subject: [PATCH] Added abstract RouteHandler and documentation. --- VERSION | 2 +- src/Routing/IRouteHandler.php | 10 +++++++++- src/Routing/Route.php | 20 ++++++++++++++++++++ src/Routing/RouteHandler.php | 14 ++++++++++++++ src/Routing/RouteHandlerTrait.php | 4 ++++ tests/RouterTest.php | 5 ++--- 6 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 src/Routing/RouteHandler.php diff --git a/VERSION b/VERSION index f7b18b5..6d1d662 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2309.72158 +0.2309.72221 diff --git a/src/Routing/IRouteHandler.php b/src/Routing/IRouteHandler.php index 3122c4d..adadb91 100644 --- a/src/Routing/IRouteHandler.php +++ b/src/Routing/IRouteHandler.php @@ -1,10 +1,18 @@ method; } + /** + * Returns the target path. + * + * @return string + */ public function getPath(): string { return $this->path; } + /** + * Reads attributes from methods in a IRouteHandler instance and registers them to a given IRouter instance. + * + * @param IRouter $router Router instance. + * @param IRouteHandler $handler Handler instance. + */ public static function handleAttributes(IRouter $router, IRouteHandler $handler): void { $objectInfo = new ReflectionObject($handler); $methodInfos = $objectInfo->getMethods(); diff --git a/src/Routing/RouteHandler.php b/src/Routing/RouteHandler.php new file mode 100644 index 0000000..5b6ed52 --- /dev/null +++ b/src/Routing/RouteHandler.php @@ -0,0 +1,14 @@ +assertEquals('avatar', $router->resolve('POST', '/avatar')->run()); $this->assertEquals('static', $router->resolve('PUT', '/static')->run()); - $badHandler = new class implements IRouteHandler { - use RouteHandlerTrait; - + $badHandler = new class extends RouteHandler { #[Route('GET', '/')] #[Route('POST', '/meow')] public function getPostBad() {