diff --git a/.htaccess b/.htaccess index 37ef9c6..cabbfde 100644 --- a/.htaccess +++ b/.htaccess @@ -3,5 +3,5 @@ RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule (.*) /index.php?route=$1 [QSA,L] +RewriteRule (.*) /index.php?routeQuery=$1 [QSA,L] \ No newline at end of file diff --git a/core/bootstrap.php b/core/bootstrap.php index 6a96c6e..dc5e7ac 100644 --- a/core/bootstrap.php +++ b/core/bootstrap.php @@ -4,6 +4,7 @@ use Core\Helpers\Cache; use Core\Template; use Core\CoreException; + use Core\Models\Router; if (session_status() == PHP_SESSION_NONE) { session_start(); @@ -65,4 +66,8 @@ } } else { $USER = null; - } \ No newline at end of file + } + + // запускаем маршрутизатор, передавая ему запрошенный адрес + Router::execute(); + die(); \ No newline at end of file diff --git a/core/lib/Core/Models/Router.class.php b/core/lib/Core/Models/Router.class.php new file mode 100644 index 0000000..d2518c0 --- /dev/null +++ b/core/lib/Core/Models/Router.class.php @@ -0,0 +1,63 @@ + $callback) { + if (preg_match($pattern, $_SERVER['REQUEST_URI'], $params)) // сравнение идет через регулярное выражение + { + array_shift($params); + return call_user_func_array($callback, array_values($params)); + } + } + + if (in_array(self::ERROR_PAGE, array_keys(self::$routes), true)) { + return self::$routes[self::ERROR_PAGE](); + } else { + return self::notFound(); + } + } + + } \ No newline at end of file diff --git a/core/routes.php b/core/routes.php index f0d879c..d262215 100644 --- a/core/routes.php +++ b/core/routes.php @@ -1,2 +1,33 @@