Support regex on config/routes.php + further wrapping of routes
This commit is contained in:
parent
d0f5ea233f
commit
beb561a5e5
|
@ -1,3 +1,5 @@
|
|||
<?php require 'base.php' ?>
|
||||
<?php session_enforce() ?>
|
||||
<?php
|
||||
|
||||
echo 'APP';
|
||||
echo $_SERVER['REQUEST_URI'];
|
||||
|
|
|
@ -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',
|
||||
],
|
||||
];
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue