VENOM: Fix Router cannot find Route if Trailing Slash is existing (VersusTuneZ)

FIX Typos
Change Folder
WIP
This commit is contained in:
engineerTrooper 2020-12-13 01:26:02 +01:00
parent 85549fbd43
commit 196ff0b1f1
7 changed files with 24 additions and 18 deletions

View file

@ -41,6 +41,7 @@ class Router
public function findRoute($url, $method): ?array public function findRoute($url, $method): ?array
{ {
$url = $this->removeIfFirst($url, $this->prefix); $url = $this->removeIfFirst($url, $this->prefix);
$url = $this->removeTrailingSlash($url);
// check if full match... this can easily done if the url isset select the empty! // check if full match... this can easily done if the url isset select the empty!
$method = strtoupper($method); $method = strtoupper($method);
$route = $this->getRouteByName($url, $method); $route = $this->getRouteByName($url, $method);
@ -64,14 +65,16 @@ class Router
return $rawString; return $rawString;
} }
/* @todo implement Security Check if SecurityModule is used */
private function getRouteByName($url, $method, $subRoute = '*', $params = []): ?array private function getRouteByName($url, $method, $subRoute = '*', $params = []): ?array
{ {
$routeAvailable = isset($this->routes[$url]); if (isset($this->routes[$url])
$subRouteFound = isset($this->routes[$url]['routes'][$subRoute]); && isset($this->routes[$url]['routes'])
$methodFound = isset($this->routes[$url]['routes'][$subRoute][$method]); && isset($this->routes[$url]['routes'][$subRoute])
if ($routeAvailable && $subRouteFound && $methodFound) { && isset($this->routes[$url]['routes'][$subRoute][$method])
if ((Config::getInstance()->getSecurity()->useSecurity || $this->id === self::ADMIN_ROUTER) && isset($this->routes[$url]['roles'])) { ) {
if ((Config::getInstance()->getSecurity()->useSecurity || $this->id === self::ADMIN_ROUTER)
&& isset($this->routes[$url]['roles'])
) {
$roles = $this->routes[$url]['roles']; $roles = $this->routes[$url]['roles'];
if (!in_array(User::GUEST_ROLE, $roles, true) && !Security::get()->hasRoles($roles)) { if (!in_array(User::GUEST_ROLE, $roles, true) && !Security::get()->hasRoles($roles)) {
return null; return null;
@ -122,4 +125,10 @@ class Router
return false; return false;
} }
} }
private function removeTrailingSlash(string $rawString)
{
$len = strlen($rawString);
return $rawString[$len - 1] === '/' ? substr($rawString, 0, strlen($rawString) - 1) : $rawString;
}
} }

View file

@ -51,7 +51,7 @@ class MetaDataModule implements Module, Route
AdminHelper::sendResponse([ AdminHelper::sendResponse([
'metaData' => [ 'metaData' => [
['id' => 1, 'name' => 'engineertrooper', 'icon' => 'vt-edit'], ['id' => 1, 'name' => 'engineertrooper', 'icon' => 'vt-edit'],
['id' => 2, 'name' => 'versustunze', 'icon' => 'vt-edit'] ['id' => 2, 'name' => 'versustunez', 'icon' => 'vt-edit']
] ]
]); ]);
} }

View file

@ -55,7 +55,7 @@ class PageModule implements Module, Route
['id' => 3, 'name' => 'Aufbau und Umbau des neuen VENOMs Plugins', 'icon' => 'vt-edit'], ['id' => 3, 'name' => 'Aufbau und Umbau des neuen VENOMs Plugins', 'icon' => 'vt-edit'],
['id' => 4, 'name' => 'Aber Mama hat gesagt!', 'icon' => 'vt-edit'], ['id' => 4, 'name' => 'Aber Mama hat gesagt!', 'icon' => 'vt-edit'],
['id' => 5, 'name' => 'Frische Fische nur heute!', 'icon' => 'vt-edit'] ['id' => 5, 'name' => 'Frische Fische nur heute!', 'icon' => 'vt-edit']
] ],
]); ]);
} }
@ -76,6 +76,10 @@ class PageModule implements Module, Route
'id' => $id, 'id' => $id,
'name' => 'Admin', 'name' => 'Admin',
'icon' => 'vt-visibility', 'icon' => 'vt-visibility',
'users' => [
['value' => 1, 'name' => 'engineertrooper', 'icon' => 'vt-edit'],
['value' => 2, 'name' => 'versustunez', 'icon' => 'vt-edit']
]
]); ]);
} }
} }

View file

@ -51,7 +51,7 @@ class UserModule implements Module, Route
AdminHelper::sendResponse([ AdminHelper::sendResponse([
'users' => [ 'users' => [
['id' => 1, 'name' => 'engineertrooper', 'icon' => 'vt-edit'], ['id' => 1, 'name' => 'engineertrooper', 'icon' => 'vt-edit'],
['id' => 2, 'name' => 'versustunze', 'icon' => 'vt-edit'] ['id' => 2, 'name' => 'versustunez', 'icon' => 'vt-edit']
] ]
]); ]);
} }

View file

@ -51,7 +51,7 @@ class VenomStatusModule implements Module, Route
AdminHelper::sendResponse([ AdminHelper::sendResponse([
'users' => [ 'users' => [
['id' => 1, 'name' => 'engineertrooper', 'icon' => 'vt-edit'], ['id' => 1, 'name' => 'engineertrooper', 'icon' => 'vt-edit'],
['id' => 2, 'name' => 'versustunze', 'icon' => 'vt-edit'] ['id' => 2, 'name' => 'versustunez', 'icon' => 'vt-edit']
] ]
]); ]);
} }

View file

@ -13,14 +13,7 @@
{include(includes/input;class=input-group;label=Page Name;name=PageName;error=Page Name is required;default=Turbinen sind geil)} {include(includes/input;class=input-group;label=Page Name;name=PageName;error=Page Name is required;default=Turbinen sind geil)}
</div> </div>
<div> <div>
<!--{include(includes/select;required=false;name=pageVisibility;label=Current Author)}--> {include(includes/select;name=pageVisibility;label=Current Author;object=$users)}
<v-select required name="pageVisibility">
<v-label empty="Current Author"></v-label>
<v-options>
<v-option value="engineertrooper">engineertrooper (Dominic Seela)</v-option>
<v-option value="versustunez">versustunez (Maurice Grönwoldt)</v-option>
</v-options>
</v-select>
</div> </div>
<div> <div>
<v-select required name="pageVisibility"> <v-select required name="pageVisibility">