1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace wapmorgan\UnifiedArchive\Commands; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
6
|
|
|
use Symfony\Component\Console\Helper\Table; |
7
|
|
|
use Symfony\Component\Console\Helper\TableCell; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
12
|
|
|
use wapmorgan\UnifiedArchive\Drivers\BasicDriver; |
13
|
|
|
use wapmorgan\UnifiedArchive\Formats; |
14
|
|
|
|
15
|
|
|
class FormatCommand extends BaseCommand |
16
|
|
|
{ |
17
|
|
|
protected static $defaultName = 'system:format'; |
18
|
|
|
|
19
|
|
|
protected function configure() |
20
|
|
|
{ |
21
|
|
|
$this |
22
|
|
|
->setDescription('Describes possible and actual format support') |
23
|
|
|
->setHelp('Describes possible and actual format support.') |
24
|
|
|
->addArgument('format', InputArgument::OPTIONAL, 'format') |
25
|
|
|
; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @throws \Exception |
30
|
|
|
*/ |
31
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
32
|
|
|
{ |
33
|
|
|
$formats = Formats::getDeclaredDriverFormats(); |
34
|
|
|
$format = $input->getArgument('format'); |
35
|
|
|
|
36
|
|
|
if (empty($format) || !isset($formats[$format])) { |
37
|
|
|
/** @var QuestionHelper $helper */ |
38
|
|
|
$helper = $this->getHelper('question'); |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
$question = new ChoiceQuestion('Which format', array_keys($formats)); |
42
|
|
|
$format = $helper->ask($input, $output, $question); |
43
|
|
|
} |
44
|
|
|
$output->writeln('Format <info>' . $format . '</info> drivers support'); |
45
|
|
|
|
46
|
|
|
$table = new Table($output); |
47
|
|
|
$table->setHeaders(['format', ...array_keys(self::$abilitiesLabels)]); |
48
|
|
|
/** |
49
|
|
|
* @var int $i |
50
|
|
|
* @var BasicDriver $driver |
51
|
|
|
*/ |
52
|
|
|
foreach ($formats[$format] as $i => $driver) { |
53
|
|
|
if ($driver::isInstalled()) { |
54
|
|
|
$abilities = $driver::checkFormatSupport($format); |
55
|
|
|
$row = [$driver]; |
56
|
|
|
|
57
|
|
|
foreach (self::$abilitiesLabels as $possibleAbility) { |
58
|
|
|
$row[] = in_array($possibleAbility, $abilities, true) ? '+' : ''; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$table->setRow($i, $row); |
62
|
|
|
} else { |
63
|
|
|
$table->setRow($i, [$driver, new TableCell('<error>not installed</error>', ['colspan' => 6])]); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
$table->render(); |
67
|
|
|
|
68
|
|
|
return 0; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|