Skip to content

Commit

Permalink
Merge pull request #6 from AfaanBilal/rl
Browse files Browse the repository at this point in the history
Updated Route List
  • Loading branch information
AneesMuzzafer authored Jan 19, 2024
2 parents 66bac69 + 267c621 commit 90cf488
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/console/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ public static function redText(string $message): string
{
return "\033[1;31m" . $message . "\033[0m";
}

public static function blueText(string $message): string
{
return "\033[1;34m" . $message . "\033[0m";
}
}
35 changes: 34 additions & 1 deletion core/console/Lister.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Lister
public function __construct()
{
$this->router = Application::getInstance()->make(Router::class);
$this->logRoutes();
$this->logAllRoutes();
}

private function logRoutes()
Expand All @@ -36,4 +36,37 @@ private function logRoutes()

console_log(Helper::greenText("\nTotal Routes = $r"));
}

private function logAllRoutes(): void
{
$allRoutes = $this->router->getRoutes();

$longestUriLength = 0;
$routeList = [];

foreach ($allRoutes as $method => $routes) {
foreach ($routes as $r) {
if ($longestUriLength < strlen($r->uri)) {
$longestUriLength = strlen($r->uri);
}

$routeList[] = [
"method" => $method,
"uri" => $r->uri,
"action" => is_array($r->action) ? basename($r->action[0]) . "@" . $r->action[1] : "(closure)",
];
}
}

$longestUriLength += 4; // 4 space offset

console_log(Helper::purpleText("Method\tURI" . str_repeat(" ", $longestUriLength - 3) . "Action"));
console_log("======\t===" . str_repeat(" ", $longestUriLength - 3) . "======");

foreach ($routeList as $r) {
$m = $r['method'] == "GET" ? Helper::greenText($r['method']) : Helper::yellowText($r['method']);

console_log($m . "\t" . $r['uri'] . str_repeat(" ", $longestUriLength - strlen($r['uri'])) . Helper::blueText($r['action']));
}
}
}

0 comments on commit 90cf488

Please sign in to comment.