addArgument('module', InputArgument::REQUIRED, 'O nome do módulo (ex: blog)')
->addArgument('name', InputArgument::REQUIRED, 'O nome do controlador (ex: PostController)');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$module = strtolower($input->getArgument('module'));
$name = $input->getArgument('name');
// Garantir que termina com Controller
if (!str_ends_with($name, 'Controller')) {
$name .= 'Controller';
}
$modulePath = dirname(__DIR__, 3) . '/modules/' . $module;
if (!is_dir($modulePath)) {
$output->writeln("O módulo '{$module}' não existe.");
return Command::FAILURE;
}
$controllersPath = $modulePath . '/classes/Controllers';
if (!is_dir($controllersPath)) {
mkdir($controllersPath, 0755, true);
}
$filePath = $controllersPath . '/' . $name . '.php';
if (file_exists($filePath)) {
$output->writeln("O controlador '{$name}' já existe no módulo '{$module}'.");
return Command::FAILURE;
}
$namespace = "Modules\\" . ucfirst($module) . "\\Controllers";
$template = <<writeln("Controlador '{$name}' criado com sucesso em modules/{$module}/classes/Controllers/");
return Command::SUCCESS;
} else {
$output->writeln("Falha ao criar o arquivo do controlador.");
return Command::FAILURE;
}
}
}