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
|
7 |
|
protected function createProgressBar(InputInterface $input, OutputInterface $output) |
50
|
|
|
{ |
51
|
7 |
|
if ($input->hasParameterOption('no-progress')) { |
52
|
|
|
$output = new NullOutput(); |
53
|
|
|
} |
54
|
|
|
|
55
|
7 |
|
$progress = new ProgressBar($output); |
56
|
7 |
|
$progress->setMessage(''); |
57
|
7 |
|
$progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %message%'); |
58
|
7 |
|
$progress->setRedrawFrequency(1); |
59
|
|
|
|
60
|
7 |
|
return $progress; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param Config\ConfigInterface $config |
65
|
|
|
*/ |
66
|
1 |
|
public function setConfig(Config\ConfigInterface $config) |
67
|
|
|
{ |
68
|
1 |
|
$this->config = $config; |
69
|
1 |
|
} |
70
|
|
|
} |
71
|
|
|
|