1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gacela\Console\Infrastructure\Command; |
6
|
|
|
|
7
|
|
|
use Gacela\Console\ConsoleFacade; |
8
|
|
|
use Gacela\Console\Domain\FilenameSanitizer\FilenameSanitizer; |
9
|
|
|
use Gacela\Framework\DocBlockResolverAwareTrait; |
10
|
|
|
use Symfony\Component\Console\Command\Command; |
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Input\InputOption; |
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @method ConsoleFacade getFacade() |
18
|
|
|
*/ |
19
|
|
|
final class MakeModuleCommand extends Command |
20
|
|
|
{ |
21
|
|
|
use DocBlockResolverAwareTrait; |
22
|
|
|
|
23
|
2 |
|
protected function configure(): void |
24
|
|
|
{ |
25
|
2 |
|
$this->setName('make:module') |
26
|
2 |
|
->setDescription('Generate a basic module with an empty ' . $this->getExpectedFilenames()) |
27
|
2 |
|
->addArgument('path', InputArgument::REQUIRED, 'The file path. For example "App/TestModule/TestSubModule"') |
28
|
2 |
|
->addOption('short-name', 's', InputOption::VALUE_NONE, 'Remove module prefix to the class name'); |
29
|
|
|
} |
30
|
|
|
|
31
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
32
|
|
|
{ |
33
|
|
|
/** @var string $path */ |
34
|
2 |
|
$path = $input->getArgument('path'); |
35
|
2 |
|
$commandArguments = $this->getFacade()->parseArguments($path); |
36
|
2 |
|
$shortName = (bool)$input->getOption('short-name'); |
37
|
|
|
|
38
|
2 |
|
foreach (FilenameSanitizer::EXPECTED_FILENAMES as $filename) { |
39
|
2 |
|
$fullPath = $this->getFacade()->generateFileContent( |
40
|
|
|
$commandArguments, |
41
|
|
|
$filename, |
42
|
|
|
$shortName |
43
|
|
|
); |
44
|
2 |
|
$output->writeln("> Path '{$fullPath}' created successfully"); |
45
|
|
|
} |
46
|
|
|
|
47
|
2 |
|
$pieces = explode('/', $commandArguments->directory()); |
48
|
2 |
|
$moduleName = end($pieces); |
49
|
2 |
|
$output->writeln("Module '{$moduleName}' created successfully"); |
50
|
|
|
|
51
|
2 |
|
return self::SUCCESS; |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
private function getExpectedFilenames(): string |
55
|
|
|
{ |
56
|
2 |
|
return implode(', ', FilenameSanitizer::EXPECTED_FILENAMES); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|