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