|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\SubCommand; |
|
4
|
|
|
|
|
5
|
|
|
use N98\Magento\Command\AbstractMagentoCommand; |
|
6
|
|
|
use Symfony\Component\Console\Helper\DialogHelper; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
|
|
10
|
|
|
abstract class AbstractSubCommand implements SubCommandInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var ConfigBag |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $config; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var array |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $commandConfig; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var InputInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $input; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var OutputInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $output; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var AbstractMagentoCommand |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $command; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param ConfigBag $config |
|
39
|
|
|
*/ |
|
40
|
|
|
public function setConfig(ConfigBag $config) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->config = $config; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param array $commandConfig |
|
47
|
|
|
*/ |
|
48
|
|
|
public function setCommandConfig(array $commandConfig) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->commandConfig = $commandConfig; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param InputInterface $input |
|
55
|
|
|
*/ |
|
56
|
|
|
public function setInput(InputInterface $input) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->input = $input; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param OutputInterface $output |
|
63
|
|
|
*/ |
|
64
|
|
|
public function setOutput(OutputInterface $output) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->output = $output; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return AbstractMagentoCommand |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getCommand() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->command; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param AbstractMagentoCommand $command |
|
79
|
|
|
*/ |
|
80
|
|
|
public function setCommand(AbstractMagentoCommand $command) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->command = $command; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return void |
|
87
|
|
|
*/ |
|
88
|
|
|
abstract public function execute(); |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param string $name of the optional option |
|
92
|
|
|
* @param string $question to ask in case the option is not available |
|
93
|
|
|
* @param bool $default value (true means yes, false no), optional, defaults to true |
|
94
|
|
|
* @return bool |
|
95
|
|
|
*/ |
|
96
|
|
|
final protected function getOptionalBooleanOption($name, $question, $default = true) |
|
97
|
|
|
{ |
|
98
|
|
|
if ($this->input->getOption($name) !== null) { |
|
99
|
|
|
$flag = $this->getCommand()->parseBoolOption($this->input->getOption($name)); |
|
100
|
|
|
|
|
101
|
|
|
return $flag; |
|
102
|
|
|
} else { |
|
103
|
|
|
/** @var $dialog DialogHelper */ |
|
104
|
|
|
$dialog = $this->getCommand()->getHelper('dialog'); |
|
105
|
|
|
|
|
106
|
|
|
$flag = $dialog->askConfirmation( |
|
107
|
|
|
$this->output, |
|
108
|
|
|
sprintf('<question>%s</question> <comment>[%s]</comment>: ', $question, $default ? 'y' : 'n'), |
|
109
|
|
|
$default |
|
110
|
|
|
); |
|
111
|
|
|
|
|
112
|
|
|
return $flag; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|