1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HotRodCli\Commands\Xml; |
4
|
|
|
|
5
|
|
|
use HotRodCli\Commands\BaseCommand; |
6
|
|
|
use HotRodCli\Jobs\Filesystem\CopyFile; |
7
|
|
|
use HotRodCli\Jobs\Module\ReplaceText; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
class CreateLayoutCommand extends BaseCommand |
13
|
|
|
{ |
14
|
|
|
protected $jobs = [ |
15
|
|
|
CopyFile::class => null, |
16
|
|
|
ReplaceText::class => null |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
protected $configs = [ |
20
|
|
|
'arguments' => [ |
21
|
|
|
[ |
22
|
|
|
'name' => 'namespace', |
23
|
|
|
'mode' => InputArgument::REQUIRED, |
24
|
|
|
'description' => 'What is the namespace on the module' |
25
|
|
|
], |
26
|
|
|
[ |
27
|
|
|
'name' => 'layout-name', |
28
|
|
|
'mode' => InputArgument::REQUIRED, |
29
|
|
|
'description' => 'name of the layout' |
30
|
|
|
], |
31
|
|
|
[ |
32
|
|
|
'name' => 'layout-file-name', |
33
|
|
|
'mode' => InputArgument::REQUIRED, |
34
|
|
|
'description' => 'name of the layout\'s file' |
35
|
|
|
], |
36
|
|
|
[ |
37
|
|
|
'name' => 'block-class', |
38
|
|
|
'mode' => InputArgument::REQUIRED, |
39
|
|
|
'description' => 'full class name of the block' |
40
|
|
|
], |
41
|
|
|
[ |
42
|
|
|
'name' => 'template', |
43
|
|
|
'mode' => InputArgument::REQUIRED, |
44
|
|
|
'description' => 'template file' |
45
|
|
|
] |
46
|
|
|
], |
47
|
|
|
'options' => [ |
48
|
|
|
[ |
49
|
|
|
'name' => 'admin', |
50
|
|
|
'shortcut' => null, |
51
|
|
|
'mode' => InputArgument::OPTIONAL, |
52
|
|
|
'description' => 'Is this layout for admin part?' |
53
|
|
|
] |
54
|
|
|
], |
55
|
|
|
'description' => 'Creates a new layout file', |
56
|
|
|
'name' => 'create:layout', |
57
|
|
|
'help' => 'creates a new controller in a given namespace with a given route' |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
public function configure() |
61
|
|
|
{ |
62
|
|
|
$this->config(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
66
|
|
|
{ |
67
|
|
|
$this->setJobs(); |
68
|
|
|
$jobs = $this->jobs; |
69
|
|
|
$namespace = explode('_', $input->getArgument('namespace')); |
70
|
|
|
$scope = $input->getOption('admin') ? 'adminhtml' : 'frontend'; |
71
|
|
|
$app = $this->appContainer; |
72
|
|
|
|
73
|
|
|
$jobs[CopyFile::class]->handle( |
74
|
|
|
$app->get('resource_dir') . '/xml/layout.xml', |
75
|
|
|
$this->appContainer->get('app_dir') |
76
|
|
|
. '/app/code/' . $namespace[0] . '/' . $namespace[1] |
77
|
|
|
. '/view/' . $scope . '/layout/' . $input->getArgument('layout-file-name') . '.xml' |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
$jobs[ReplaceText::class]->handle( |
81
|
|
|
'{{block_class}}', |
82
|
|
|
$input->getArgument('block-class'), |
83
|
|
|
$this->appContainer->get('app_dir') . '/app/code/' . $namespace[0] . '/' . $namespace[1] . '/view/' |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
$jobs[ReplaceText::class]->handle( |
87
|
|
|
'{{block_name}}', |
88
|
|
|
strtolower($input->getArgument('layout-name')), |
89
|
|
|
$this->appContainer->get('app_dir') . '/app/code/' . $namespace[0] . '/' . $namespace[1] . '/view/' |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
$jobs[ReplaceText::class]->handle( |
93
|
|
|
'{{block_template}}', |
94
|
|
|
$namespace[0] . '_' . $namespace[1] . '::' . $input->getArgument('template') . '.phtml', |
95
|
|
|
$this->appContainer->get('app_dir') . '/app/code/' . $namespace[0] . '/' . $namespace[1] . '/view/' |
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
$output->writeln('<info>' |
99
|
|
|
. $namespace[0] . '/' |
100
|
|
|
. $namespace[1] . '/view/frontend/layout/' |
101
|
|
|
. strtolower($input->getArgument('layout-file-name')) . '.xml was successfully created</info>'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|