1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace wapmorgan\UnifiedArchive\Commands; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
11
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
12
|
|
|
use wapmorgan\UnifiedArchive\Formats; |
13
|
|
|
|
14
|
|
|
class DetailsCommand extends BaseFileCommand |
15
|
|
|
{ |
16
|
|
|
protected static $defaultName = 'file:details'; |
17
|
|
|
|
18
|
|
|
protected function configure() |
19
|
|
|
{ |
20
|
|
|
parent::configure(); |
21
|
|
|
$this |
22
|
|
|
->setDescription('Renders detailed information about file within archive') |
23
|
|
|
->setHelp('Renders detailed information about file within archive.') |
24
|
|
|
->addOption('detect-mimetype', null, InputOption::VALUE_NONE, 'Detect mimetype for entries by its raw content') |
25
|
|
|
; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
|
|
list($archive, $file) = $this->getArchiveAndFile($input, $output); |
31
|
|
|
$detect_mimetype = $input->getOption('detect-mimetype'); |
32
|
|
|
|
33
|
|
|
$details = $archive->getFileData($file); |
34
|
|
|
$output->writeln('File <info>' . $file . '</info>'); |
35
|
|
|
if ($detect_mimetype) { |
36
|
|
|
$output->writeln('Mime type: <info>' . $this->getMimeTypeByStream($archive->getFileStream($file)).'</info>'); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$output->writeln('Size:'); |
40
|
|
|
$output->writeln("\t". 'uncompressed: '.implode(' ', $this->formatSize($details->uncompressedSize, 2))); |
41
|
|
|
$output->writeln("\t" . 'compressed: ' . implode(' ', $this->formatSize($details->compressedSize, 2))); |
42
|
|
|
$output->writeln("\t" . 'ratio: <info>' . round($details->uncompressedSize / $details->compressedSize, 6) . '/1 (' . floor($details->compressedSize / $details->uncompressedSize * 100) . '%</info>)'); |
43
|
|
|
$output->writeln('Modificated: ' . $this->formatDate($details->modificationTime)); |
44
|
|
|
if (!empty($comment = $details->comment)) |
45
|
|
|
$output->writeln('Comment: <comment>' . $comment . '</comment>'); |
46
|
|
|
|
47
|
|
|
if (empty($input->getArgument('file'))) { |
48
|
|
|
$helper = $this->getHelper('question'); |
49
|
|
|
$question = new ConfirmationQuestion('Another file? [y/N] ', false); |
50
|
|
|
|
51
|
|
|
if ($helper->ask($input, $output, $question)) { |
52
|
|
|
$this->execute($input, $output); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return 0; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|