corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-17 a212c53dc537ce66800b8e987fb18b1aab994bb4
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] . ">[a-z]+)";
                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";
    }
}