1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* (c) Waarneembemiddeling.nl |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
namespace Wb\Bundle\BigRegisterBundle\Command; |
9
|
|
|
|
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
use Wb\BigRegister\SoapClient\Exception\ConnectionException; |
15
|
|
|
use Wb\BigRegister\SoapClient\Service; |
16
|
|
|
|
17
|
|
|
class GetBigResultByNumberCommand extends ContainerAwareCommand |
18
|
|
|
{ |
19
|
|
|
protected function configure() |
20
|
|
|
{ |
21
|
|
|
$this |
22
|
|
|
->setName('wb:big:by-number') |
23
|
|
|
->setDescription('Fetch big register data by big number') |
24
|
|
|
->addArgument('number', InputArgument::REQUIRED) |
25
|
|
|
; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
|
|
/** @var Service $bigService */ |
31
|
|
|
$bigService = $this->getContainer()->get('wb_big_register.service'); |
32
|
|
|
$number = $input->getArgument('number'); |
33
|
|
|
|
34
|
|
|
try { |
35
|
|
|
$bigResult = $bigService->findByRegistrationNumber($number); |
36
|
|
|
} catch (ConnectionException $e) { |
37
|
|
|
$output->writeln(sprintf('Error: %s', $e->getMessage())); |
38
|
|
|
|
39
|
|
|
return; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if ($bigResult) { |
43
|
|
|
$formatter = function($value, $key) use ($output, &$formatter) { |
44
|
|
|
if (is_scalar($value)) { |
45
|
|
|
$output->writeln(sprintf('%s: %s', $key, $value)); |
46
|
|
|
} elseif(is_array($value)) { |
47
|
|
|
$output->writeln(sprintf('%s:', $key)); |
48
|
|
|
array_walk($value, $formatter); |
49
|
|
|
} elseif ($value instanceof \DateTime) { |
50
|
|
|
$output->writeln(sprintf('%s: %s', $key, $value->format(\DateTime::ISO8601))); |
51
|
|
|
} |
52
|
|
|
}; |
53
|
|
|
|
54
|
|
|
array_walk($bigResult, $formatter); |
55
|
|
|
} else { |
56
|
|
|
$output->writeln('No bigResult found'); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|