|
|
|
|
@ -410,13 +410,11 @@ class router |
|
|
|
|
* with a method called get! |
|
|
|
|
*/ |
|
|
|
|
private static function get_all_routes(bool $testing = false) { |
|
|
|
|
$request = trim(self::$REQUEST, '/'); |
|
|
|
|
$prj = explode('/', $request)[0]; |
|
|
|
|
$safe_prj = \tts\security::filter_class($prj); |
|
|
|
|
if (!empty($safe_prj)) { |
|
|
|
|
$prj = rtrim(\tts\site_helper::get_project(), '/'); |
|
|
|
|
if (!empty($prj)) { |
|
|
|
|
$route_name = (\tts\console_app::is_cli()) ? "cli_routes" : "routes"; |
|
|
|
|
$routes = ($testing) ? "test_routes" : $route_name; |
|
|
|
|
$routes_class = "\\prj\\{$safe_prj}\\routes\\{$routes}"; |
|
|
|
|
$routes_class = "\\prj\\{$prj}\\routes\\{$routes}"; |
|
|
|
|
|
|
|
|
|
if (class_exists($routes_class)) { |
|
|
|
|
if (method_exists($routes_class, "get")) { |
|
|
|
|
@ -430,7 +428,7 @@ class router |
|
|
|
|
/** |
|
|
|
|
* Execute router |
|
|
|
|
*/ |
|
|
|
|
public static function execute(): bool { |
|
|
|
|
public static function execute() { |
|
|
|
|
$ROOT = \tts\site_helper::get_root(); |
|
|
|
|
$request_uri = \tts\site_helper::get_uri(); |
|
|
|
|
$request_method = \tts\site_helper::get_method(); |
|
|
|
|
@ -537,8 +535,10 @@ class router |
|
|
|
|
|
|
|
|
|
// Call action |
|
|
|
|
if (is_callable($route['action'])) { |
|
|
|
|
call_user_func_array($route['action'], $resortedParams); |
|
|
|
|
$returned = call_user_func_array($route['action'], $resortedParams); |
|
|
|
|
return ["found"=> true, "returned"=> $returned]; |
|
|
|
|
} else if (strpos($route['action'], '@') !== false) { |
|
|
|
|
|
|
|
|
|
// call controller |
|
|
|
|
list($controller, $method) = explode('@', $route['action']); |
|
|
|
|
|
|
|
|
|
@ -559,12 +559,12 @@ class router |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Call method |
|
|
|
|
call_user_func_array([$controller, $method], $resortedParams); |
|
|
|
|
$returned = call_user_func_array([$controller, $method], $resortedParams); |
|
|
|
|
return ["found"=> true, "returned"=> $returned]; |
|
|
|
|
} |
|
|
|
|
return true; // Worked |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
return ["found"=>false]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|