Support regex on config/routes.php + further wrapping of routes

This commit is contained in:
Niko 2022-02-10 10:38:16 +01:00
parent d0f5ea233f
commit beb561a5e5
3 changed files with 22 additions and 11 deletions

View File

@ -1,3 +1,5 @@
<?php require 'base.php' ?>
<?php session_enforce() ?>
<?php
echo 'APP';
echo $_SERVER['REQUEST_URI'];

View File

@ -1,12 +1,15 @@
<?php
// Documentation:
// to use REGEX, use ^ at the start of path
global $routes;
$routes = [
'root' => [
'/' => 'public.home',
],
'app' => [
'/' => 'app.app',
'/login' => 'public.login',
'^\/.*$' => 'app.app',
],
];

View File

@ -37,13 +37,19 @@ function module($ns, $die = false) {
# module ROUTING
module('config.routes');
foreach ($routes['root'] as $path => $module)
if ($uri === $path)
$routes_config = [
[ 'name' => 'root', 'base_uri' => $uri ],
[ 'name' => 'app', 'base_uri' => $app_uri ],
];
foreach ($routes_config as $rcfg) {
foreach ($routes[$rcfg['name']] as $path => $module) {
if (substr($path, 0, 1) === '^' &&
preg_match('/'.$path.'/', $rcfg['base_uri']))
module($module, true);
foreach ($routes['app'] as $path => $module)
if ($app_uri === $path)
if ($rcfg['base_uri'] === $path)
module($module, true);
}
}
# /@username