From 2bd6cf89f6f71f4d221c7661af823dcf448f22fe Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Fri, 29 Nov 2024 18:21:08 +0200 Subject: [PATCH] Adds phpdoc comments --- app/classes/router.php | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/app/classes/router.php b/app/classes/router.php index f600ee4..9005ed6 100644 --- a/app/classes/router.php +++ b/app/classes/router.php @@ -1,13 +1,37 @@ routes[$pattern] = $callback; } + /** + * Dispatches a request to the appropriate route callback. + * + * @param string $url The URL to match against the defined routes. + * + * @return void Outputs the result of the invoked callback or a 404 error if no route matches. + */ public function dispatch($url) { // remove variables from url $url = strtok($url, '?'); @@ -25,9 +49,18 @@ class Router { echo '404 page not found'; } + /** + * Invokes the callback for a matched route. + * + * @param string $callback The callback for the route in the format "Controller@Method". + * @param array $params Parameters extracted from the route pattern. + * + * @return void Executes the specified method on the specified controller with the provided parameters. + * + * @throws Exception If the controller class or method does not exist. + */ private function invoke($callback, $params) { list($controllerName, $methodName) = explode('@', $callback); -// $controllerClass = "\\App\\Controllers\\$controllerName"; $controllerClass = "../pages/$pageName"; $controller = new $controllerClass(); call_user_func_array([$controller, $methodName], $params);