Fixed Routes on Tests

main
Robert 3 years ago
parent c182381396
commit 6228982c69
  1. 9
      src/bootstrap/site_helper.php
  2. 20
      src/classes/router.php

@ -218,9 +218,12 @@ final class site_helper {
self::set_params();
self::set_route();
define('PROJECT_ASSETS_BASE_REF', "/assets/" . self::$PRJ);
define('ASSETS_BASE_REF', "/assets/");
if (! defined("PROJECT_ASSETS_BASE_REF")) {
define('PROJECT_ASSETS_BASE_REF', "/assets/" . self::$PRJ);
}
if (! defined("ASSETS_BASE_REF")) {
define('ASSETS_BASE_REF', "/assets/");
}
}
public static function set_project_namespace() {

@ -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];
}
/**

Loading…
Cancel
Save