From b619b4bb0387536f931977d70b7f1920c413a669 Mon Sep 17 00:00:00 2001 From: absurdo Date: Wed, 25 Oct 2023 21:20:21 +0200 Subject: [PATCH] Fixes in routes for load from vendor directory for use composer for distribute modules --- libraries/Routes.php | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/libraries/Routes.php b/libraries/Routes.php index d59b1d0..2161bb3 100644 --- a/libraries/Routes.php +++ b/libraries/Routes.php @@ -7,7 +7,7 @@ class Config { static public $home_module='welcome'; - static public $modules_allowed=['welcome']; + static public $modules_allowed=['welcome' => 'modules/welcome']; static public $base_url=''; @@ -17,6 +17,7 @@ class Config { * Url: http://domain.com/ * Url: http://domain.com/index.php/{module} * Url: http://domain.com/index.php/{module}/app/{arg1}/{arg2} -> modules/module/controller_app.php controller($args); +* Url: http://domain.com/index.php/{module}/index/{arg1}/{arg2} -> modules/module/controller_index.php AppController->App($args); */ function get_controller($controller, $args=[]) { @@ -65,17 +66,19 @@ function get_route($path_info) { case 0: - $controller='modules/'.\PhangoApp\PhaRouter\Config::$home_module.'/controllers/app.php'; + $controller=\PhangoApp\PhaRouter\Config::$home_module.'/controllers/app.php'; return \PhangoApp\PhaRouter\get_controller($controller, []); break; case 1: + + if(isset(Config::$modules_allowed[$arr_path[1]])) { + + $module_path=Config::$modules_allowed[$arr_path[1]]; - $controller='modules/'.$arr_path[1].'/controllers/app.php'; - - if(in_array($arr_path[1], Config::$modules_allowed)) { + $controller=$module_path.'/controllers/app.php'; return \PhangoApp\PhaRouter\get_controller($controller, []); @@ -84,11 +87,13 @@ function get_route($path_info) { break; case 2: + + if(isset(Config::$modules_allowed[$arr_path[1]])) { - $controller='modules/'.$arr_path[1].'/controllers/'.$arr_path[2].'.php'; - - if(in_array($arr_path[1], Config::$modules_allowed)) { - + $module_path=Config::$modules_allowed[$arr_path[1]]; + + $controller=$module_path.'/controllers/'.$arr_path[2].'.php'; + return \PhangoApp\PhaRouter\get_controller($controller, []); } @@ -96,10 +101,12 @@ function get_route($path_info) { break; default: - - $controller='modules/'.$arr_path[1].'/controllers/'.$arr_path[2].'.php'; - - if(in_array($arr_path[1], Config::$modules_allowed)) { + + if(isset(Config::$modules_allowed[$arr_path[1]])) { + + $module_path=Config::$modules_allowed[$arr_path[1]]; + + $controller=$module_path.'/controllers/'.$arr_path[2].'.php'; $args=array_slice($arr_path, 2, count($arr_path)); @@ -114,7 +121,7 @@ function get_route($path_info) { } else { - $controller='modules/'.\PhangoApp\PhaRouter\Config::$home_module.'/controllers/app.php'; + $controller=\PhangoApp\PhaRouter\Config::$home_module.'/controllers/app.php'; return \PhangoApp\PhaRouter\get_controller($controller, []);