54 lines
1.6 KiB
PHP
Executable File
54 lines
1.6 KiB
PHP
Executable File
<?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;
|
|
|
|
class EnvListCommand extends Command
|
|
{
|
|
protected static $defaultName = 'env:list';
|
|
protected static $defaultDescription = 'Lista as variáveis de ambiente carregadas do .env';
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$output->writeln('<info>Variáveis de Ambiente (.env):</info>');
|
|
|
|
$envFile = dirname(__DIR__, 3) . '/.env';
|
|
|
|
if (!file_exists($envFile)) {
|
|
$output->writeln('<error>Arquivo .env não encontrado.</error>');
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
$table = new Table($output);
|
|
$table->setHeaders(['Variável', 'Valor']);
|
|
|
|
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
|
|
foreach ($lines as $line) {
|
|
// Ignorar comentários
|
|
if (str_starts_with(trim($line), '#')) {
|
|
continue;
|
|
}
|
|
|
|
if (str_contains($line, '=')) {
|
|
[$key, $value] = explode('=', $line, 2);
|
|
|
|
// Ocultar senhas e chaves sensíveis por segurança
|
|
if (preg_match('/(PASSWORD|SECRET|KEY|TOKEN)/i', $key)) {
|
|
$value = '********';
|
|
}
|
|
|
|
$table->addRow([trim($key), trim($value, '"\' ')]);
|
|
}
|
|
}
|
|
|
|
$table->render();
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|