50 lines
1.6 KiB
PHP
Executable File
50 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
class AppRenameCommand extends Command
|
|
{
|
|
protected static $defaultName = 'app:rename';
|
|
protected static $defaultDescription = 'Altera o nome da aplicação no arquivo .env';
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this
|
|
->addArgument('name', InputArgument::REQUIRED, 'O novo nome da aplicação');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$newName = $input->getArgument('name');
|
|
$envFile = dirname(__DIR__, 3) . '/.env';
|
|
|
|
if (!file_exists($envFile)) {
|
|
$output->writeln('<error>Arquivo .env não encontrado.</error>');
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
$content = file_get_contents($envFile);
|
|
$pattern = "/APP_NAME=(.*)/";
|
|
$replacement = "APP_NAME=\"{$newName}\"";
|
|
|
|
if (preg_match($pattern, $content)) {
|
|
$newContent = preg_replace($pattern, $replacement, $content);
|
|
} else {
|
|
$newContent = $content . "\nAPP_NAME=\"{$newName}\"";
|
|
}
|
|
|
|
if (file_put_contents($envFile, $newContent)) {
|
|
$output->writeln("<info>Aplicação renomeada para '{$newName}' com sucesso!</info>");
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
$output->writeln('<error>Falha ao renomear a aplicação.</error>');
|
|
return Command::FAILURE;
|
|
}
|
|
}
|