From a5cd6071298cdeaa1c3da28f2445f67c7d504043 Mon Sep 17 00:00:00 2001 From: Skylear Date: Thu, 15 Jul 2021 12:01:41 -0500 Subject: [PATCH] Refactor $callback to $action --- .gitignore | 1 + src/Splashsky/Router.php | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index be2b7ed..b1e43c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store ._* /vendor/ +/src/Splashsky/test.php \ No newline at end of file diff --git a/src/Splashsky/Router.php b/src/Splashsky/Router.php index 3a9a6dd..8726691 100644 --- a/src/Splashsky/Router.php +++ b/src/Splashsky/Router.php @@ -8,23 +8,23 @@ class Router private static $pathNotFound; private static $methodNotAllowed; - public static function add(string $route, callable $callback, string $method = 'get') + public static function add(string $route, callable $action, string $method = 'get') { self::$routes[] = [ 'route' => $route, - 'callback' => $callback, + 'action' => $action, 'method' => $method ]; } - public static function get(string $route, callable $callback) + public static function get(string $route, callable $action) { - self::add($route, $callback, 'get'); + self::add($route, $action, 'get'); } - public static function post(string $route, callable $callback) + public static function post(string $route, callable $action) { - self::add($route, $callback, 'post'); + self::add($route, $action, 'post'); } public static function getAllRoutes() @@ -32,14 +32,14 @@ class Router return self::$routes; } - public static function pathNotFound(callable $callback) + public static function pathNotFound(callable $action) { - self::$pathNotFound = $callback; + self::$pathNotFound = $action; } - public static function methodNotAllowed(callable $callback) + public static function methodNotAllowed(callable $action) { - self::$methodNotAllowed = $callback; + self::$methodNotAllowed = $action; } public static function run(string $basePath = '', bool $caseMatters = false, bool $trailingSlashMatters = false, bool $multimatch = false) @@ -73,6 +73,8 @@ class Router // Add string start and end automatically $route['route'] = '^'.$route['route'].'$'; + + die('#'.$route['route'].'#'.($caseMatters ? '' : 'i').'u'); // Check path match if (preg_match('#'.$route['route'].'#'.($caseMatters ? '' : 'i').'u', $path, $matches)) { @@ -88,7 +90,7 @@ class Router array_shift($matches); // Remove basepath } - if ($return = call_user_func_array($route['callback'], $matches)) { + if ($return = call_user_func_array($route['action'], $matches)) { echo $return; }