|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace wapmorgan\UnifiedArchive\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
use wapmorgan\UnifiedArchive\Drivers\BasicDriver; |
|
10
|
|
|
use wapmorgan\UnifiedArchive\Formats; |
|
11
|
|
|
|
|
12
|
|
|
class BaseArchiveCommand extends BaseCommand |
|
13
|
|
|
{ |
|
14
|
|
|
protected function configure() |
|
15
|
|
|
{ |
|
16
|
|
|
parent::configure(); |
|
17
|
|
|
$this |
|
18
|
|
|
->addArgument('archive', InputArgument::REQUIRED, 'Archive file') |
|
19
|
|
|
->addOption('password', null, InputOption::VALUE_REQUIRED, 'Password for archive') |
|
20
|
|
|
; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param InputInterface $input |
|
25
|
|
|
* @param OutputInterface $output |
|
26
|
|
|
* @return \wapmorgan\UnifiedArchive\UnifiedArchive |
|
27
|
|
|
* @throws \Exception |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function getArchive(InputInterface $input, OutputInterface $output) |
|
30
|
|
|
{ |
|
31
|
|
|
$file = realpath($input->getArgument('archive')); |
|
|
|
|
|
|
32
|
|
|
$output->writeln('<comment>Opening ' . $file . '</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
33
|
|
|
if (!is_file($file)) { |
|
34
|
|
|
throw new \InvalidArgumentException('File ' . $input->getArgument('archive') . ' is not accessible'); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
$output->writeln('<comment>Format ' . Formats::detectArchiveFormat($file).'</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
37
|
|
|
$password = $input->getOption('password'); |
|
38
|
|
|
if (empty($password)) { |
|
39
|
|
|
$password = null; |
|
40
|
|
|
} else { |
|
41
|
|
|
$output->writeln('<comment>Passing password: ' . strlen($password).'</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
42
|
|
|
} |
|
43
|
|
|
$archive = $this->open($file, $password); |
|
44
|
|
|
$output->writeln('<comment>Driver ' . $archive->getDriverType() . '</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
45
|
|
|
$output->writeln('<comment>Driver abilities: ' . implode(', ', $this->getDriverFormatAbilities($archive->getDriverType(), $archive->getFormat())) . '</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
|
|
|
|
|
46
|
|
|
return $archive; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param BasicDriver $driver |
|
51
|
|
|
* @param $format |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function getDriverFormatAbilities($driver, $format) |
|
55
|
|
|
{ |
|
56
|
|
|
$abilities = $driver::checkFormatSupport($format); |
|
57
|
|
|
return array_keys(array_intersect(self::$abilitiesLabels, $abilities)); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|