-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRouteListCommand.php
82 lines (67 loc) · 2.55 KB
/
RouteListCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
declare(strict_types=1);
namespace Hyde\Console\Commands;
use Hyde\Console\Concerns\Command;
use Hyde\Hyde;
use Hyde\Pages\InMemoryPage;
use Hyde\Support\Models\Route;
use Hyde\Support\Models\RouteList;
use Hyde\Support\Models\RouteListItem;
use function file_exists;
use function sprintf;
/**
* Hyde command to display the list of site routes.
*
* @see \Hyde\Framework\Testing\Feature\Commands\RouteListCommandTest
*/
class RouteListCommand extends Command
{
/** @var string */
protected $signature = 'route:list';
/** @var string */
protected $description = 'Display all registered routes.';
public function handle(): int
{
$routes = $this->routeListClass();
$this->table($routes->headers(), $routes->toArray());
return Command::SUCCESS;
}
protected function routeListClass(): RouteList
{
return new class extends RouteList
{
protected static function routeToListItem(Route $route): RouteListItem
{
return new class($route) extends RouteListItem
{
protected function stylePageType(string $class): string
{
$type = parent::stylePageType($class);
$page = $this->route->getPage();
/** @experimental The typeLabel macro is experimental */
if ($page instanceof InMemoryPage && $page->hasMacro('typeLabel')) {
$type .= sprintf(' <fg=gray>(%s)</>', $page->__call('typeLabel', []));
}
return $type;
}
protected function styleSourcePath(string $path): string
{
return parent::styleSourcePath($path) !== 'none'
? $this->href(Command::fileLink(Hyde::path($path)), $path)
: '<fg=gray>none</>';
}
protected function styleOutputPath(string $path): string
{
return file_exists(Hyde::sitePath($path))
? $this->href(Command::fileLink(Hyde::sitePath($path)), parent::styleOutputPath($path))
: parent::styleOutputPath($path);
}
protected function href(string $link, string $label): string
{
return "<href=$link>$label</>";
}
};
}
};
}
}