2024-01-18 11:49:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
2024-02-06 16:24:57 +01:00
|
|
|
function initRouter(): array
|
2024-01-31 22:05:23 +01:00
|
|
|
{
|
2024-01-18 11:49:38 +01:00
|
|
|
global $routerConfig;
|
2024-02-06 16:24:57 +01:00
|
|
|
$routerRequest = array();
|
2024-01-18 11:49:38 +01:00
|
|
|
|
|
|
|
$routerRequest["requestAddress"] = array_slice(explode('.', $_SERVER['HTTP_HOST']), -3, 3); //get the last 3 elements
|
|
|
|
|
2024-02-06 16:24:57 +01:00
|
|
|
$request_uri = explode("/", $_SERVER["QUERY_STRING"]);
|
2024-01-18 11:49:38 +01:00
|
|
|
|
2024-02-06 16:29:26 +01:00
|
|
|
echo $_SERVER["QUERY_STRING"];
|
2024-02-06 16:28:59 +01:00
|
|
|
print_r($request_uri);
|
2024-02-06 16:24:57 +01:00
|
|
|
$request_uri = array_slice($request_uri, -3, 3);
|
2024-02-06 16:28:36 +01:00
|
|
|
print_r($request_uri);
|
2024-01-18 11:49:38 +01:00
|
|
|
|
2024-02-06 16:24:57 +01:00
|
|
|
$routerRequest["site_name"] = basename($request_uri[1]);
|
|
|
|
$routerRequest["page_name"] = basename($request_uri[2]);
|
2024-02-02 15:57:26 +01:00
|
|
|
|
2024-02-06 16:24:57 +01:00
|
|
|
if (empty($routerRequest["site_name"])) {
|
|
|
|
$routerRequest["site_name"] = $routerConfig["default_site"];
|
2024-02-02 15:55:23 +01:00
|
|
|
}
|
2024-02-02 15:57:26 +01:00
|
|
|
|
2024-02-02 15:53:32 +01:00
|
|
|
if (empty($routerRequest["page_name"])) {
|
|
|
|
$routerRequest["page_name"] = $routerConfig["default_page"];
|
2024-01-18 11:49:38 +01:00
|
|
|
}
|
|
|
|
|
2024-02-06 16:24:57 +01:00
|
|
|
if($_SERVER["REQUEST_METHOD"] == "POST"){
|
|
|
|
$routerRequest["type"] = "api";
|
2024-01-18 11:49:38 +01:00
|
|
|
}
|
2024-02-06 16:24:57 +01:00
|
|
|
if(empty($routerRequest["type"])) {
|
|
|
|
$routerRequest["type"] = "page";
|
2024-01-18 11:49:38 +01:00
|
|
|
}
|
2024-02-06 16:24:57 +01:00
|
|
|
|
|
|
|
return $routerRequest;
|
2024-01-18 11:49:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|