1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace wapmorgan\UnifiedArchive\Commands; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Helper\Table; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use wapmorgan\UnifiedArchive\Abilities; |
10
|
|
|
use wapmorgan\UnifiedArchive\Drivers\Basic\BasicDriver; |
11
|
|
|
use wapmorgan\UnifiedArchive\Formats; |
12
|
|
|
|
13
|
|
|
class FormatsCommand extends BaseCommand |
14
|
|
|
{ |
15
|
|
|
protected static $defaultName = 'system:formats'; |
16
|
|
|
|
17
|
|
|
protected function configure() |
18
|
|
|
{ |
19
|
|
|
$this |
20
|
|
|
->setDescription('Lists supported archive formats with current system configuration') |
21
|
|
|
->setHelp('Lists supported archive formats with current system configuration. You can check supported formats and supported actions with them.') |
22
|
|
|
->addArgument('driver', InputArgument::OPTIONAL, 'Filter formats support by specific driver') |
23
|
|
|
->addUsage('\'wapmorgan\UnifiedArchive\Drivers\SevenZip\'') |
24
|
|
|
; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
28
|
|
|
{ |
29
|
|
|
$table = new Table($output); |
30
|
|
|
|
31
|
|
|
/** @var string|BasicDriver $driver */ |
32
|
|
|
$driver = $input->getArgument('driver'); |
33
|
|
|
|
34
|
|
|
if ($driver !== null) { |
|
|
|
|
35
|
|
|
$driver = $this->resolveDriverName($driver); |
36
|
|
|
if (!class_exists($driver) || !is_a($driver, BasicDriver::class, true)) { |
37
|
|
|
throw new \InvalidArgumentException('Class "' . $driver . '" not found or not in BasicDriver children'); |
38
|
|
|
} |
39
|
|
|
$output->writeln('Supported formats by <info>' . $driver . '</info>'); |
40
|
|
|
|
41
|
|
|
$headers = array_keys(Abilities::$abilitiesLabels); |
42
|
|
|
array_unshift($headers, 'format'); |
43
|
|
|
$table->setHeaders($headers); |
44
|
|
|
foreach ($driver::getFormats() as $i => $format) { |
45
|
|
|
$abilities = $driver::getFormatAbilities($format); |
46
|
|
|
$row = [$format]; |
47
|
|
|
|
48
|
|
|
foreach (Abilities::$abilitiesLabels as $possibleAbility) { |
49
|
|
|
$row[] = in_array($possibleAbility, $abilities, true) ? '+' : ''; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$table->setRow($i, $row); |
53
|
|
|
} |
54
|
|
|
$table->render(); |
55
|
|
|
return 0; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$formats = Formats::getSupportedDriverFormats(); |
59
|
|
|
$headers = array_keys($formats); |
60
|
|
|
array_unshift($headers, 'driver type'); |
61
|
|
|
array_unshift($headers, 'driver / format'); |
62
|
|
|
$table->setHeaders($headers); |
63
|
|
|
$rows = []; |
64
|
|
|
|
65
|
|
|
/** @var \wapmorgan\UnifiedArchive\Drivers\Basic\BasicDriver $driverClass */ |
66
|
|
|
foreach (Formats::$drivers as $driverClass) { |
67
|
|
|
$row = [ |
68
|
|
|
substr($driverClass, strrpos($driverClass, '\\') + 1), |
69
|
|
|
BasicDriver::$typeLabels[$driverClass::TYPE], |
70
|
|
|
]; |
71
|
|
|
foreach ($formats as $format => $formatSupportStatus) { |
72
|
|
|
if (isset($formatSupportStatus[$driverClass])) { |
73
|
|
|
$shortcuts = null; |
74
|
|
|
foreach (Abilities::$abilitiesShortCuts as $ability => $abilitiesShortCut) { |
75
|
|
|
if (in_array($ability, $formatSupportStatus[$driverClass], true)) { |
76
|
|
|
$shortcuts .= $abilitiesShortCut; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
$row[] = $shortcuts; |
80
|
|
|
} else { |
81
|
|
|
$row[] = ''; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
$rows[] = $row; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$table->setRows($rows); |
88
|
|
|
//$table->setRow($i++, $row); |
89
|
|
|
$table->render(); |
90
|
|
|
|
91
|
|
|
foreach (array_combine(array_values(Abilities::$abilitiesShortCuts), array_keys( |
92
|
|
|
Abilities::$abilitiesLabels |
93
|
|
|
)) as $shortCut => $label) { |
94
|
|
|
$output->writeln('<info>' . $shortCut . '</info> - ' . $label); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return 0; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|