1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Ship\Command; |
4
|
|
|
|
5
|
|
|
use Rudra\Container\Facades\Rudra; |
6
|
|
|
use Rudra\Cli\ConsoleFacade as Cli; |
7
|
|
|
use Rudra\Router\RouterFacade as Router; |
8
|
|
|
|
9
|
|
|
class RouterCommand |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Returns all routes |
13
|
|
|
* ------------------ |
14
|
|
|
* Возвращает все маршруты |
15
|
|
|
*/ |
16
|
|
|
public function actionIndex(): void |
17
|
|
|
{ |
18
|
|
|
$_SERVER["REQUEST_METHOD"] = 'GET'; |
19
|
|
|
$_SERVER["REQUEST_URI"] = ''; |
20
|
|
|
|
21
|
|
|
foreach (Rudra::config()->get('containers') as $container => $item) { |
22
|
|
|
$mask = "|%-3.3s|%-45.45s|%-7.7s|%-65.65s|%-25.25s| x |" . PHP_EOL; |
23
|
|
|
Cli::printer(strtoupper($container) . PHP_EOL, "yellow"); |
24
|
|
|
printf("\e[5;35m" . $mask . "\e[m", " ", "route", "method", "controller", "action"); |
25
|
|
|
$this->getTable($this->getRoutes($container)); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Returns the route of the module |
31
|
|
|
* ------------------------------- |
32
|
|
|
* Возвращает маршрут модуля |
33
|
|
|
*/ |
34
|
|
|
public function actionContainer(): void |
35
|
|
|
{ |
36
|
|
|
$_SERVER["REQUEST_METHOD"] = 'GET'; |
37
|
|
|
$_SERVER["REQUEST_URI"] = ''; |
38
|
|
|
|
39
|
|
|
Cli::printer("Enter container name: ", "magneta"); |
40
|
|
|
$link = trim(Cli::reader()); |
41
|
|
|
$mask = "|%-3.3s|%-45.45s|%-7.7s|%-65.65s|%-25.25s| x |" . PHP_EOL; |
42
|
|
|
printf("\e[5;35m" . $mask . "\e[m", " ", "route", "method", "controller", "action"); |
43
|
|
|
$this->getTable($this->getRoutes($link)); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Forms a table |
48
|
|
|
* ------------- |
49
|
|
|
* Формирует таблицу |
50
|
|
|
* |
51
|
|
|
* @param array $data |
52
|
|
|
*/ |
53
|
|
|
protected function getTable(array $data): void |
54
|
|
|
{ |
55
|
|
|
$mask = "|%-3.3s|%-45.45s|%-7.7s|%-65.65s|%-25.25s| x |" . PHP_EOL; |
56
|
|
|
$i = 1; |
57
|
|
|
|
58
|
|
|
foreach ($data as $routes) { |
59
|
|
|
printf("\e[5;36m" . $mask . "\e[m", $i, $routes[0]['url'], $routes[0]['method'], $routes[0]['controller'], $routes[0]['action'] ?? "actionIndex"); |
60
|
|
|
$i++; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Builds route files from modules |
66
|
|
|
* ------------------------------- |
67
|
|
|
* Собирает файлы маршрутов из модулей |
68
|
|
|
* |
69
|
|
|
* @param string $container |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
protected function getRoutes(string $container): array |
73
|
|
|
{ |
74
|
|
|
$path = "app/Containers/" . ucfirst($container) . "/routes"; |
75
|
|
|
|
76
|
|
|
if (file_exists($path . ".php")) { |
77
|
|
|
return Router::annotationCollector(require $path . ".php", true, Rudra::config()->get("attributes")); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return []; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.