First Commit
This commit is contained in:
Executable
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Kernel\Application;
|
||||
|
||||
class DebugRouterCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'debug:router';
|
||||
protected static $defaultDescription = 'Lista detalhes das rotas registradas na aplicação';
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$app = Application::getInstance();
|
||||
if (!$app) {
|
||||
$output->writeln('<error>Não foi possível obter a instância da aplicação.</error>');
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$routes = $app->getRoutes();
|
||||
|
||||
$output->writeln('<info>Rotas Registradas:</info>');
|
||||
|
||||
$table = new Table($output);
|
||||
$table->setHeaders(['Método', 'Caminho', 'Handler']);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
[$method, $path, $handler] = $route;
|
||||
|
||||
$handlerStr = is_array($handler) ? implode('@', $handler) : 'Closure';
|
||||
$table->addRow([$method, $path, $handlerStr]);
|
||||
}
|
||||
|
||||
$table->render();
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user