First Commit
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
<?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 DebugContainerCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'debug:container';
|
||||
protected static $defaultDescription = 'Lista todos os serviços registrados no container de injeção de dependência';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$container = $app->getContainer();
|
||||
|
||||
// PHP-DI doesn't easily expose all registered definitions unless we use internal reflection
|
||||
// or a specific configuration. For simplicity in this environment, we'll list what's common.
|
||||
|
||||
$output->writeln('<info>Serviços no Container DI:</info>');
|
||||
|
||||
$table = new Table($output);
|
||||
$table->setHeaders(['ID', 'Status']);
|
||||
|
||||
$commonServices = [
|
||||
\DI\Container::class,
|
||||
\Kernel\Application::class,
|
||||
\Kernel\ModuleLoader::class,
|
||||
\Kernel\View::class,
|
||||
'db',
|
||||
'logging',
|
||||
'mailer'
|
||||
];
|
||||
|
||||
foreach ($commonServices as $service) {
|
||||
$status = $container->has($service) ? '<info>Registrado</info>' : '<comment>Não definido</comment>';
|
||||
$table->addRow([$service, $status]);
|
||||
}
|
||||
|
||||
$table->render();
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user