|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace uuf6429\ElderBrother\Action; |
|
4
|
|
|
|
|
5
|
|
|
use Psr\Log; |
|
6
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
use uuf6429\ElderBrother\Config; |
|
11
|
|
|
|
|
12
|
|
|
abstract class ActionAbstract implements Config\ConfigAwareInterface, Log\LoggerAwareInterface |
|
13
|
|
|
{ |
|
14
|
|
|
use Log\LoggerAwareTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var Config\ConfigInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $config; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Returns name of this action (possibly with some extra info). |
|
23
|
|
|
* |
|
24
|
|
|
* @return string |
|
25
|
|
|
*/ |
|
26
|
|
|
abstract public function getName(); |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Returns false when action is not supported (eg: missing lib etc). |
|
30
|
|
|
* |
|
31
|
|
|
* @return bool |
|
32
|
|
|
*/ |
|
33
|
|
|
abstract public function isSupported(); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Execute action for the given parameters. |
|
37
|
|
|
* |
|
38
|
|
|
* @param InputInterface $input |
|
39
|
|
|
* @param OutputInterface $output |
|
40
|
|
|
*/ |
|
41
|
|
|
abstract public function execute(InputInterface $input, OutputInterface $output); |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param InputInterface $input |
|
45
|
|
|
* @param OutputInterface $output |
|
46
|
|
|
* |
|
47
|
|
|
* @return ProgressBar |
|
48
|
|
|
*/ |
|
49
|
9 |
|
protected function createProgressBar(InputInterface $input, OutputInterface $output) |
|
50
|
|
|
{ |
|
51
|
9 |
|
if ($input->hasParameterOption('no-progress')) { |
|
52
|
|
|
$output = new NullOutput(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
9 |
|
$progress = new ProgressBar($output); |
|
56
|
9 |
|
$progress->setMessage(''); |
|
57
|
9 |
|
$progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %message%'); |
|
58
|
9 |
|
$progress->setRedrawFrequency(1); |
|
59
|
|
|
|
|
60
|
9 |
|
return $progress; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param Config\ConfigInterface $config |
|
65
|
|
|
*/ |
|
66
|
4 |
|
public function setConfig(Config\ConfigInterface $config) |
|
67
|
|
|
{ |
|
68
|
4 |
|
$this->config = $config; |
|
69
|
4 |
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|