-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateFileHashesCommand.php
More file actions
49 lines (39 loc) · 1.54 KB
/
GenerateFileHashesCommand.php
File metadata and controls
49 lines (39 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Gared\EtherScan\Console;
use Gared\EtherScan\Service\FileHashLookupService;
use Gared\EtherScan\Service\StaticFileClient;
use GuzzleHttp\Client;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: 'ether:generate-file-hashes',
description: 'Generate file hashes of given instance'
)]
class GenerateFileHashesCommand extends Command
{
protected function configure(): void
{
$this->addArgument('url', InputArgument::REQUIRED, 'Url to etherpad instance');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$url = $input->getArgument('url');
$fileHashLookup = new FileHashLookupService();
$staticFileClient = new StaticFileClient(new Client());
$files = FileHashLookupService::getFileNames();
$tableRows = [];
foreach ($files as $file) {
$fileHash = $staticFileClient->getFileHash($url, $file);
$versionRange = $fileHashLookup->getEtherpadVersionRange($file, $fileHash);
$tableRows[] = [$file, $fileHash, $versionRange];
}
$symfonyStyle = new SymfonyStyle($input, $output);
$symfonyStyle->table(['File', 'Hash', 'Version'], $tableRows);
return self::SUCCESS;
}
}