1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HotRodCli\Commands\Classes; |
4
|
|
|
|
5
|
|
|
use HotRodCli\Commands\BaseCommand; |
6
|
|
|
use HotRodCli\Jobs\Filesystem\CopyFile; |
7
|
|
|
use HotRodCli\Jobs\Module\IsModuleExists; |
8
|
|
|
use HotRodCli\Jobs\Module\ReplaceText; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
12
|
|
|
|
13
|
|
|
class CreateHelperCommand extends BaseCommand |
14
|
|
|
{ |
15
|
|
|
protected $jobs = [ |
16
|
|
|
IsModuleExists::class => null, |
17
|
|
|
CopyFile::class => null, |
18
|
|
|
ReplaceText::class => null |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
protected function configure() |
22
|
|
|
{ |
23
|
|
|
$this->setName('create:helper') |
24
|
|
|
->setDescription('Creates a new helper') |
25
|
|
|
->addArgument( |
26
|
|
|
'namespace', |
27
|
|
|
InputArgument::REQUIRED, |
28
|
|
|
'What is the namespace on the new module' |
29
|
|
|
) |
30
|
|
|
->addArgument( |
31
|
|
|
'name', |
32
|
|
|
InputArgument::REQUIRED, |
33
|
|
|
'What is the name of the new helper' |
34
|
|
|
) |
35
|
|
|
->setHelp('creates a new helper in a given namespace'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
39
|
|
|
{ |
40
|
|
|
$this->setJobs(); |
41
|
|
|
|
42
|
|
|
try { |
43
|
|
|
$this->processHelperFile($input, $output); |
44
|
|
|
} catch (\Throwable $e) { |
45
|
|
|
$output->writeln('<error>' . $e->getMessage() . '</error>'); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function processHelperFile(InputInterface $input, OutputInterface $output) |
50
|
|
|
{ |
51
|
|
|
$this->setJobs(); |
52
|
|
|
$namespace = explode('_', $input->getArgument('namespace')); |
53
|
|
|
$name = $input->getArgument('name'); |
54
|
|
|
|
55
|
|
|
$this->jobs[IsModuleExists::class]->handle( |
56
|
|
|
$input->getArgument('namespace'), |
57
|
|
|
$output |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$this->jobs[CopyFile::class]->handle( |
61
|
|
|
$this->appContainer->get('resource_dir') . '/classes/Helper.tphp', |
62
|
|
|
$this->appContainer->get('app_dir') . '/app/code/' . $namespace[0] . '/' . $namespace[1] . '/Helper/' . $name . '.php' |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$this->replaceTextsSequence([ |
66
|
|
|
'{{namespace}}' => str_replace('_', '\\', $input->getArgument('namespace')), |
67
|
|
|
'{{className}}' => $name, |
68
|
|
|
], $this->appContainer->get('app_dir') . '/app/code/' . $namespace[0] . '/' . $namespace[1] . '/Helper/'); |
69
|
|
|
|
70
|
|
|
$output->writeln('<info>Helper ' . $input->getArgument('name') . ' was successfully created</info>'); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|