wapmorgan /
UnifiedArchive
| 1 | <?php |
||
| 2 | |||
| 3 | namespace wapmorgan\UnifiedArchive\Commands; |
||
| 4 | |||
| 5 | use Symfony\Component\Console\Helper\FormatterHelper; |
||
| 6 | use Symfony\Component\Console\Helper\Table; |
||
| 7 | use Symfony\Component\Console\Input\InputInterface; |
||
| 8 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 9 | use wapmorgan\UnifiedArchive\Drivers\Basic\BasicDriver; |
||
| 10 | use wapmorgan\UnifiedArchive\Formats; |
||
| 11 | |||
| 12 | class DriversCommand extends BaseCommand |
||
| 13 | { |
||
| 14 | protected static $defaultName = 'system:drivers'; |
||
| 15 | |||
| 16 | protected function configure() |
||
| 17 | { |
||
| 18 | $this |
||
| 19 | ->setDescription('Lists supported drivers for different formats and their installation status in system') |
||
| 20 | ->setHelp('Lists supported drivers for different formats and their installation status in system. You need to manually install any of them.') |
||
| 21 | ; |
||
| 22 | } |
||
| 23 | |||
| 24 | public function execute(InputInterface $input, OutputInterface $output) |
||
| 25 | { |
||
| 26 | $notInstalled = []; |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 27 | $drivers = []; |
||
| 28 | /** @var FormatterHelper $formatter */ |
||
| 29 | $formatter = $this->getHelper('formatter'); |
||
|
0 ignored issues
–
show
|
|||
| 30 | |||
| 31 | /** @var \wapmorgan\UnifiedArchive\Drivers\Basic\BasicDriver $driverClass */ |
||
| 32 | foreach (Formats::$drivers as $driverClass) { |
||
| 33 | $description = $driverClass::getDescription(); |
||
| 34 | if (!$driverClass::isInstalled()) { |
||
| 35 | $drivers[$driverClass::TYPE][$driverClass] = [$description, false, $driverClass::getInstallationInstruction()]; |
||
| 36 | // $notInstalled[] = [$driverClass, $description, $install]; |
||
| 37 | } else { |
||
| 38 | $drivers[$driverClass::TYPE][$driverClass] = [$description, true]; |
||
| 39 | } |
||
| 40 | |||
| 41 | // if (!empty($install)) { |
||
| 42 | // } else { |
||
| 43 | // $output->writeln($formatter->formatSection($driverClass, $description) . ': ' . implode(', ', $driverClass::getFormats())); |
||
| 44 | // } |
||
| 45 | } |
||
| 46 | |||
| 47 | /** @var FormatterHelper $formatter */ |
||
| 48 | $formatter = $this->getHelper('formatter'); |
||
| 49 | |||
| 50 | $table = new Table($output); |
||
| 51 | $table->setStyle('compact'); |
||
| 52 | $table->setHeaders(['driver', 'type', 'description / installation']); |
||
| 53 | |||
| 54 | $i = 0; |
||
| 55 | foreach ($drivers as $type => $typeDrivers) { |
||
| 56 | /** |
||
| 57 | * @var \wapmorgan\UnifiedArchive\Drivers\Basic\BasicDriver $typeDriverClass |
||
| 58 | * @var array $typeDriverConfig |
||
| 59 | */ |
||
| 60 | foreach ($typeDrivers as $typeDriverClass => $typeDriverConfig) { |
||
| 61 | |||
| 62 | $type_messages = []; |
||
|
0 ignored issues
–
show
|
|||
| 63 | if ($typeDriverConfig[1]) { |
||
| 64 | // $type_messages[] = '<info>' . $typeDriverClass . '</info>: ' . $typeDriverConfig[0]; |
||
| 65 | $table->setRow($i++, [ |
||
| 66 | '<info>' . $this->getDriverBaseName($typeDriverClass) . '</info>', |
||
| 67 | BasicDriver::$typeLabels[$typeDriverClass::TYPE], |
||
| 68 | $typeDriverConfig[0], |
||
| 69 | ]); |
||
| 70 | } else { |
||
| 71 | // $type_messages[] = '<error>' . $typeDriverClass . '</error>: ' . $typeDriverConfig[0]; |
||
| 72 | // $type_messages[] = $this->formatInstallation($typeDriverConfig[2], 4); |
||
| 73 | $table->setRow($i++, [ |
||
| 74 | '<comment>' . $this->getDriverBaseName($typeDriverClass) . '</comment>', |
||
| 75 | BasicDriver::$typeLabels[$typeDriverClass::TYPE], |
||
| 76 | $this->formatInstallation($typeDriverConfig[2], 0), |
||
| 77 | ]); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | $table->render(); |
||
| 82 | |||
| 83 | // if (!empty($notInstalled)) { |
||
| 84 | // foreach ($notInstalled as $data) { |
||
| 85 | // $output->writeln($formatter->formatSection($data[0], $data[1] . ': ' . implode(', ', $data[0]::getFormats()), 'error')); |
||
| 86 | // $data[2] = preg_replace('~`(.+?)`~', '<options=bold,underscore>$1</>', $data[2]); |
||
| 87 | // $output->writeln($formatter->formatSection($data[0], $data[2], 'comment')); |
||
| 88 | // } |
||
| 89 | // } |
||
| 90 | |||
| 91 | return 0; |
||
| 92 | } |
||
| 93 | |||
| 94 | protected function formatInstallation($doc, $leftPadding = 4) |
||
| 95 | { |
||
| 96 | return implode("\n", array_map( |
||
| 97 | function($line) use ($leftPadding) { return str_repeat(' ', $leftPadding) . $line; }, |
||
| 98 | explode( |
||
| 99 | "\n", |
||
| 100 | preg_replace('~`(.+?)`~', '<options=bold,underscore>$1</>', $doc) |
||
| 101 | ) |
||
| 102 | )); |
||
| 103 | } |
||
| 104 | } |
||
| 105 |