Improved kernel routing system
This commit is contained in:
parent
a3c0ac7ab6
commit
8718c099f8
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
echo 'APP';
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
global $routes;
|
||||
$routes = [
|
||||
'root' => [
|
||||
'/' => 'public.home',
|
||||
],
|
||||
'app' => [
|
||||
'/' => 'app.app',
|
||||
'/login' => 'public.login',
|
||||
],
|
||||
];
|
|
@ -13,23 +13,33 @@ if ($env === PROD) {
|
|||
ini_set('display_errors', 0);
|
||||
}
|
||||
|
||||
$uri = rtrim(trim($_SERVER['REQUEST_URI']),'/');
|
||||
$s_uri = preg_replace('/^'.preg_quote(
|
||||
$uri = rtrim(trim($_SERVER['REQUEST_URI']),'/');
|
||||
$app_uri = preg_replace('/^'.preg_quote(
|
||||
APP_DIR,'/').'\//', '/', $uri);
|
||||
if ($app_uri === APP_DIR)
|
||||
$app_uri = '/';
|
||||
|
||||
function req_pub($name) { require "public/$name.php"; die; }
|
||||
function redirect($url) { header('Location: '.$url); die; }
|
||||
|
||||
|
||||
# Public URLs
|
||||
switch ($s_uri)
|
||||
{
|
||||
case '/': req_pub('home');
|
||||
case '/login': req_pub('login');
|
||||
function module($ns, $die = false) {
|
||||
require_once str_replace('.','/',$ns).'.php';
|
||||
if ($die) die;
|
||||
}
|
||||
|
||||
|
||||
# Example: /@username
|
||||
################
|
||||
# module ROUTING
|
||||
|
||||
module('config.routes');
|
||||
foreach ($routes['root'] as $path => $module)
|
||||
if ($uri === $path)
|
||||
module($module, true);
|
||||
|
||||
foreach ($routes['app'] as $path => $module)
|
||||
if ($app_uri === $path)
|
||||
module($module, true);
|
||||
|
||||
|
||||
# /@username
|
||||
if (preg_match('/^\/\@[a-zA-Z0-9\-\_]+/', $uri))
|
||||
{
|
||||
if ($_SERVER['HTTP_ACCEPT'] === 'application/activity+json')
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
echo 'HOME';
|
Loading…
Reference in New Issue