73 lines
1.9 KiB
PHP
Executable File
73 lines
1.9 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 MakeHelperCommand extends Command
|
|
{
|
|
protected static $defaultName = 'make:helper';
|
|
protected static $defaultDescription = 'Cria um novo arquivo de helper';
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this
|
|
->addArgument('name', InputArgument::REQUIRED, 'O nome do arquivo helper (ex: string_helpers)');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$name = $input->getArgument('name');
|
|
|
|
if (!str_ends_with($name, '.php')) {
|
|
$name .= '.php';
|
|
}
|
|
|
|
$directory = dirname(__DIR__, 2) . '/Helpers';
|
|
$filePath = $directory . '/' . $name;
|
|
|
|
if (file_exists($filePath)) {
|
|
$output->writeln("<error>O helper '{$name}' já existe!</error>");
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
if (!is_dir($directory)) {
|
|
mkdir($directory, 0755, true);
|
|
}
|
|
|
|
$year = date('Y');
|
|
$template = <<<PHP
|
|
<?php
|
|
|
|
/**
|
|
* SysCMS - Content Management System
|
|
*
|
|
* Copyright (c) {$year} Marco Costa
|
|
* All rights reserved.
|
|
*/
|
|
|
|
if (!function_exists('your_function_name')) {
|
|
/**
|
|
* Helper description.
|
|
*/
|
|
function your_function_name()
|
|
{
|
|
//
|
|
}
|
|
}
|
|
PHP;
|
|
|
|
if (file_put_contents($filePath, $template)) {
|
|
$output->writeln("<info>Helper '{$name}' criado com sucesso em app/Helpers/</info>");
|
|
$output->writeln("<comment>Lembre-se de incluir o arquivo no composer.json ou carregar manualmente.</comment>");
|
|
return Command::SUCCESS;
|
|
} else {
|
|
$output->writeln("<error>Falha ao criar o arquivo do helper.</error>");
|
|
return Command::FAILURE;
|
|
}
|
|
}
|
|
}
|