First Commit
This commit is contained in:
+74
@@ -0,0 +1,74 @@
|
||||
<?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 MakeRepositoryCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'make:repository';
|
||||
protected static $defaultDescription = 'Cria uma nova classe de repositório';
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->addArgument('name', InputArgument::REQUIRED, 'O nome da classe de repositório (ex: UserRepository)');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$name = $input->getArgument('name');
|
||||
|
||||
if (!str_ends_with($name, 'Repository')) {
|
||||
$name .= 'Repository';
|
||||
}
|
||||
|
||||
$directory = dirname(__DIR__, 2) . '/Repositories';
|
||||
$filePath = $directory . '/' . $name . '.php';
|
||||
|
||||
if (file_exists($filePath)) {
|
||||
$output->writeln("<error>O repositório '{$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\Repositories;
|
||||
|
||||
class {$name}
|
||||
{
|
||||
/**
|
||||
* Repository logic here.
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
// Return all records
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
|
||||
if (file_put_contents($filePath, $template)) {
|
||||
$output->writeln("<info>Repositório '{$name}' criado com sucesso em app/Repositories/</info>");
|
||||
return Command::SUCCESS;
|
||||
} else {
|
||||
$output->writeln("<error>Falha ao criar o arquivo do repositório.</error>");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user