67 lines
1.6 KiB
PHP
Executable File
67 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 MakeTraitCommand extends Command
|
|
{
|
|
protected static $defaultName = 'make:trait';
|
|
protected static $defaultDescription = 'Cria uma nova Trait PHP';
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this
|
|
->addArgument('name', InputArgument::REQUIRED, 'O nome da trait (ex: HasUuid)');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$name = $input->getArgument('name');
|
|
|
|
$directory = dirname(__DIR__, 2) . '/Traits';
|
|
$filePath = $directory . '/' . $name . '.php';
|
|
|
|
if (file_exists($filePath)) {
|
|
$output->writeln("<error>A trait '{$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.
|
|
*/
|
|
|
|
namespace App\Traits;
|
|
|
|
trait {$name}
|
|
{
|
|
/**
|
|
* Trait logic here.
|
|
*/
|
|
}
|
|
PHP;
|
|
|
|
if (file_put_contents($filePath, $template)) {
|
|
$output->writeln("<info>Trait '{$name}' criada com sucesso em app/Traits/</info>");
|
|
return Command::SUCCESS;
|
|
} else {
|
|
$output->writeln("<error>Falha ao criar o arquivo da trait.</error>");
|
|
return Command::FAILURE;
|
|
}
|
|
}
|
|
}
|