Почему может не работать функция
matchRoute()
?
Router.php<?php
class Router {
protected static $routes = [];
protected static $route = [];
public static function add($regexp, $route = []) {
self::$routes[$regexp] = $route;
}
public static function getRoutes() {
return self::$routes;
}
public static function getRoute() {
return self::$route;
}
public static function matchRoute($url) {
foreach(self::$routes as $pattern => $route) {
if($url == $pattern) {
self::$route = $route;
return true;
}
}
return false;
}
}
?>
index.php<?php
$query = $_SERVER['REQUEST_URI'];
require '../vendor/core/Router.php';
require '../vendor/libs/functions.php';
Router::add('posts/add', ['controller' => 'Posts', 'action' => 'add']);
Router::add('posts/', ['controller' => 'Posts', 'action' => 'index']);
Router::add('', ['controller' => 'Main', 'action' => 'index']);
debug(Router::getRoutes());
if(Router::matchRoute($query)) {
debug(Router::getRoute());
} else {
echo '404';
}
?>