From a26040f4846abcc8a8f8e81eb2d6d7923c384fdb Mon Sep 17 00:00:00 2001 From: filippo.bertilotti <filippobertilotti@gmail.com> Date: Tue, 21 May 2024 11:26:04 +0200 Subject: [PATCH] funzione getTable che permette di prendere il nome della tabella (parte 122) --- src/Framework/router.php | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Framework/router.php b/src/Framework/router.php index 980acf7..63596c4 100644 --- a/src/Framework/router.php +++ b/src/Framework/router.php @@ -12,15 +12,14 @@ } - public function match (string $path,): array|bool { - + public function match (string $path): array|bool { + $path = urldecode($path); + $path = trim($path, "/"); foreach ($this->routes as $route) { $pattern = $this->getPatternFromRoutePath($route["path"]); - - echo $pattern, "\n"; if(preg_match($pattern, $path, $matches)) { $matches = array_filter($matches, "is_string", ARRAY_FILTER_USE_KEY); @@ -42,11 +41,14 @@ $segments = array_map(function(string $segment) :string { if(preg_match("#^\{([a-z][a-z0-9]*)\}$#", $segment, $matches)) { - $segment = "(?<" . $matches[1] . ">[^/]*)"; + return "(?<" . $matches[1] . ">[^/]*)"; + } + if(preg_match("#^\{([a-z][a-z0-9]*):(.+)\}$#", $segment, $matches)) { + return "(?<" . $matches[1] . ">". $matches[2] ."[^/]*)"; } return $segment; }, $segments); - return "#^" . implode("/", $segments) . "$#"; + return "#^" . implode("/", $segments) . "$#iu"; } } \ No newline at end of file -- Gitblit v1.8.0