Fixes in routes for load from vendor directory for use composer for distribute modules

This commit is contained in:
absurdo 2023-10-25 21:20:21 +02:00
parent a6a95e0027
commit b619b4bb03

View file

@ -7,7 +7,7 @@ class Config {
static public $home_module='welcome'; static public $home_module='welcome';
static public $modules_allowed=['welcome']; static public $modules_allowed=['welcome' => 'modules/welcome'];
static public $base_url=''; static public $base_url='';
@ -17,6 +17,7 @@ class Config {
* Url: http://domain.com/ * Url: http://domain.com/
* Url: http://domain.com/index.php/{module} * 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}/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=[]) { function get_controller($controller, $args=[]) {
@ -65,17 +66,19 @@ function get_route($path_info) {
case 0: 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, []); return \PhangoApp\PhaRouter\get_controller($controller, []);
break; break;
case 1: 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'; $controller=$module_path.'/controllers/app.php';
if(in_array($arr_path[1], Config::$modules_allowed)) {
return \PhangoApp\PhaRouter\get_controller($controller, []); return \PhangoApp\PhaRouter\get_controller($controller, []);
@ -84,11 +87,13 @@ function get_route($path_info) {
break; break;
case 2: case 2:
if(isset(Config::$modules_allowed[$arr_path[1]])) {
$controller='modules/'.$arr_path[1].'/controllers/'.$arr_path[2].'.php'; $module_path=Config::$modules_allowed[$arr_path[1]];
if(in_array($arr_path[1], Config::$modules_allowed)) { $controller=$module_path.'/controllers/'.$arr_path[2].'.php';
return \PhangoApp\PhaRouter\get_controller($controller, []); return \PhangoApp\PhaRouter\get_controller($controller, []);
} }
@ -96,10 +101,12 @@ function get_route($path_info) {
break; break;
default: default:
$controller='modules/'.$arr_path[1].'/controllers/'.$arr_path[2].'.php'; if(isset(Config::$modules_allowed[$arr_path[1]])) {
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';
$args=array_slice($arr_path, 2, count($arr_path)); $args=array_slice($arr_path, 2, count($arr_path));
@ -114,7 +121,7 @@ function get_route($path_info) {
} }
else { 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, []); return \PhangoApp\PhaRouter\get_controller($controller, []);