First Commit
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
<?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 MakeInterfaceCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'make:interface';
|
||||
protected static $defaultDescription = 'Cria uma nova interface PHP';
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->addArgument('name', InputArgument::REQUIRED, 'O nome da interface (ex: PaymentInterface)');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$name = $input->getArgument('name');
|
||||
|
||||
if (!str_ends_with($name, 'Interface')) {
|
||||
$name .= 'Interface';
|
||||
}
|
||||
|
||||
$directory = dirname(__DIR__, 2) . '/Interfaces';
|
||||
$filePath = $directory . '/' . $name . '.php';
|
||||
|
||||
if (file_exists($filePath)) {
|
||||
$output->writeln("<error>A interface '{$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\Interfaces;
|
||||
|
||||
interface {$name}
|
||||
{
|
||||
/**
|
||||
* Define interface methods.
|
||||
*/
|
||||
}
|
||||
PHP;
|
||||
|
||||
if (file_put_contents($filePath, $template)) {
|
||||
$output->writeln("<info>Interface '{$name}' criada com sucesso em app/Interfaces/</info>");
|
||||
return Command::SUCCESS;
|
||||
} else {
|
||||
$output->writeln("<error>Falha ao criar o arquivo da interface.</error>");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user