-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveCrudCommand.php
More file actions
67 lines (58 loc) · 2.78 KB
/
Copy pathRemoveCrudCommand.php
File metadata and controls
67 lines (58 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace App\CMCommand;
use Symfony\Component\Process\Process;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Process\Exception\ProcessFailedException;
class RemoveCrudCommand extends Command
{
protected static $defaultName = 'crudmick:removeEntity';
protected static $defaultDescription = 'remove entitie with controller, repository, form and template';
protected function configure()
{
$this
->setDescription(self::$defaultDescription)
->addArgument('arg1', InputArgument::OPTIONAL, 'name of entitie')
->addOption('save', null, InputOption::VALUE_NONE, 'conserv the entity');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$fs = new Filesystem();
$io = new SymfonyStyle($input, $output);
$arg1 = $input->getArgument('arg1');
if ($arg1) {
$nom = ucfirst("$arg1");
$helper = $this->getHelper('question');
if (!$input->getOption('save'))
$question = new ConfirmationQuestion("Supprimer l'entité " . $nom . ", son controller, ses templates, son repository et son formtype (y/N)?", false);
else
$question = new ConfirmationQuestion("Conserve l'entité " . $nom . " mais supprime son controller, ses templates, son repository et son formtype (y/N)?", false);
if ($helper->ask($input, $output, $question)) {
#suppression de l'entité
$min = strtolower($nom);
$io->note(sprintf('Remove controller %s ', $nom . 'Controller.php')); // + );
$fs->remove('src/Controller/' . $nom . 'Controller.php');
$io->note("Remove Repository $nom Repository");
$fs->remove('src/Repository/' . $nom . 'Repository.php');
$io->note("Remove Form $nom Type");
$fs->remove('src/Form/' . $nom . 'Type.php');
$io->note("Remove Templates $min");
$fs->remove('templates/' . $min);
if (!$input->getOption('save')) {
$io->note("Remove Entity");
$fs->remove('src/Entity/' . $nom . '.php');
}
}
} else
$io->error('Please get the name of entitie');
return Command::SUCCESS;
}
}