1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Damax\Services\Client\Bridge\Symfony\Console\Command; |
6
|
|
|
|
7
|
|
|
use Damax\Services\Client\Client; |
8
|
|
|
use Damax\Services\Client\InvalidRequestException; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
14
|
|
|
|
15
|
|
|
final class MvdLookupCommand extends Command |
16
|
|
|
{ |
17
|
|
|
protected static $defaultName = 'damax:mvd:passport:lookup'; |
18
|
|
|
|
19
|
|
|
private $client; |
20
|
|
|
|
21
|
|
|
public function __construct(Client $client) |
22
|
|
|
{ |
23
|
|
|
parent::__construct(); |
24
|
|
|
|
25
|
|
|
$this->client = $client; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function configure() |
29
|
|
|
{ |
30
|
|
|
$this |
31
|
|
|
->setDescription('Lookup invalid passport.') |
32
|
|
|
->addArgument('number', InputArgument::REQUIRED, 'Passport number.') |
33
|
|
|
; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
37
|
|
|
{ |
38
|
|
|
$io = new SymfonyStyle($input, $output); |
39
|
|
|
|
40
|
|
|
try { |
41
|
|
|
$result = $this->client->checkPassport((string) $input->getArgument('number'))->toArray(); |
42
|
|
|
} catch (InvalidRequestException $e) { |
43
|
|
|
$io->error($e->getMessage()); |
44
|
|
|
|
45
|
|
|
return 1; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$row = function ($value, string $key): array { |
49
|
|
|
return [$key, is_bool($value) ? ($value ? '+' : '-') : $value]; |
50
|
|
|
}; |
51
|
|
|
|
52
|
|
|
$io = new SymfonyStyle($input, $output); |
53
|
|
|
$io->newLine(); |
54
|
|
|
$io->table(['Field', 'Value'], array_map($row, $result, array_keys($result))); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|