39 lines
887 B
PHP
39 lines
887 B
PHP
<?php
|
|
|
|
|
|
function initRouter(): array
|
|
{
|
|
global $routerConfig;
|
|
$routerRequest = array();
|
|
|
|
$routerRequest["requestAddress"] = array_slice(explode('.', $_SERVER['HTTP_HOST']), -3, 3); //get the last 3 elements
|
|
|
|
$request_uri = explode("/", $_SERVER["QUERY_STRING"]);
|
|
|
|
$request_uri = array_slice($request_uri, -3, 3);
|
|
|
|
|
|
$routerRequest["site_name"] = $routerConfig["default_site"];
|
|
$routerRequest["page_name"] = $routerConfig["default_page"];
|
|
|
|
if(count($request_uri) > 2){
|
|
$routerRequest["page_name"] = basename($request_uri[2]);
|
|
}
|
|
if(count($request_uri) > 1){
|
|
$routerRequest["site_name"] = basename($request_uri[1]);
|
|
|
|
}
|
|
|
|
if($_SERVER["REQUEST_METHOD"] == "POST"){
|
|
$routerRequest["type"] = "api";
|
|
}
|
|
|
|
if(empty($routerRequest["type"])) {
|
|
$routerRequest["type"] = "page";
|
|
}
|
|
|
|
return $routerRequest;
|
|
}
|
|
|
|
|