Browse Source

Router: Simplify respond logic

master
Riyyi 2 years ago
parent
commit
a0d302daec
  1. 25
      app/classes/Router.php

25
app/classes/Router.php

@ -176,33 +176,25 @@ class Router {
$controller = '\App\Controllers\\' . $controller;
$controller = new $controller(self::$router);
$stillValid = true;
// If method does not exist in object
if (!method_exists($controller, $action)) {
$stillValid = false;
return $controller->throw404();
}
// If no valid permissions
if ($controller->getAdminSection() &&
$controller->getLoggedIn() == false) {
$stillValid = false;
return $controller->throw404();
}
// Call Controller action
if ($stillValid) {
// Loop through params
$params = [];
foreach ($param as $name) {
$params[] = $request->param($name);
}
// Call Controller action
return $controller->{$action}(...$params);
}
else {
$controller->throw404();
}
});
}
@ -227,21 +219,18 @@ class Router {
$route[2] .= 'Action';
}
$stillValid = true;
// If method does not exist in object
if (!method_exists($controller, $route[2])) {
$stillValid = false;
return $controller->throw404();
}
// If no valid permissions
if ($controller->getAdminSection() &&
$controller->getLoggedIn() == false) {
$stillValid = false;
return $controller->throw404();
}
// Call Controller action
if ($stillValid) {
if (is_array($route[3])) {
return $controller->{$route[2]}(
$route[3][0] ?? '',
@ -255,10 +244,6 @@ class Router {
else {
return $controller->{$route[2]}();
}
}
else {
$controller->throw404();
}
});
}

Loading…
Cancel
Save