From beb561a5e551567e243b5435fbfb31411fe87be3 Mon Sep 17 00:00:00 2001 From: Niko Date: Thu, 10 Feb 2022 10:38:16 +0100 Subject: [PATCH] Support regex on config/routes.php + further wrapping of routes --- web/src/app/app.php | 4 +++- web/src/config/routes.php | 9 ++++++--- web/src/index.php | 20 +++++++++++++------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/web/src/app/app.php b/web/src/app/app.php index ce9bbb6..3f7ae5f 100644 --- a/web/src/app/app.php +++ b/web/src/app/app.php @@ -1,3 +1,5 @@ + + [ - '/' => 'public.home', + '/' => 'public.home', ], 'app' => [ - '/' => 'app.app', - '/login' => 'public.login', + '/login' => 'public.login', + '^\/.*$' => 'app.app', ], ]; diff --git a/web/src/index.php b/web/src/index.php index 24563f4..6053ec7 100644 --- a/web/src/index.php +++ b/web/src/index.php @@ -37,13 +37,19 @@ function module($ns, $die = false) { # 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); +$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); + if ($rcfg['base_uri'] === $path) + module($module, true); + } +} # /@username