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
|
<?php
|
||||||
|
|
||||||
echo 'APP';
|
echo $_SERVER['REQUEST_URI'];
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// Documentation:
|
||||||
|
// to use REGEX, use ^ at the start of path
|
||||||
|
|
||||||
global $routes;
|
global $routes;
|
||||||
$routes = [
|
$routes = [
|
||||||
'root' => [
|
'root' => [
|
||||||
'/' => 'public.home',
|
'/' => 'public.home',
|
||||||
],
|
],
|
||||||
'app' => [
|
'app' => [
|
||||||
'/' => 'app.app',
|
|
||||||
'/login' => 'public.login',
|
'/login' => 'public.login',
|
||||||
|
'^\/.*$' => 'app.app',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -37,13 +37,19 @@ function module($ns, $die = false) {
|
||||||
# module ROUTING
|
# module ROUTING
|
||||||
|
|
||||||
module('config.routes');
|
module('config.routes');
|
||||||
foreach ($routes['root'] as $path => $module)
|
$routes_config = [
|
||||||
if ($uri === $path)
|
[ '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);
|
module($module, true);
|
||||||
|
if ($rcfg['base_uri'] === $path)
|
||||||
foreach ($routes['app'] as $path => $module)
|
|
||||||
if ($app_uri === $path)
|
|
||||||
module($module, true);
|
module($module, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# /@username
|
# /@username
|
||||||
|
|
Loading…
Reference in New Issue