|
1
|
|
|
<?php
|
|
2
|
|
|
|
|
3
|
|
|
namespace h4kuna\Ares;
|
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp;
|
|
6
|
|
|
|
|
7
|
|
|
/**
|
|
8
|
|
|
* @author Milan Matějček <[email protected]>
|
|
9
|
|
|
*/
|
|
10
|
|
|
class Ares
|
|
11
|
|
|
{
|
|
12
|
|
|
|
|
13
|
|
|
const URL = 'http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_bas.cgi';
|
|
14
|
|
|
|
|
15
|
|
|
/** @var DataProvider */
|
|
16
|
|
|
private $dataProvider;
|
|
17
|
|
|
|
|
18
|
|
|
/** @var bool */
|
|
19
|
|
|
private $activeMode;
|
|
20
|
|
|
|
|
21
|
|
|
public function __construct(DataProvider $dataProvider = NULL)
|
|
22
|
|
|
{
|
|
23
|
|
|
if ($dataProvider === NULL) {
|
|
24
|
|
|
$dataProvider = $this->createDataProvider();
|
|
25
|
|
|
}
|
|
26
|
|
|
$this->dataProvider = $dataProvider;
|
|
27
|
|
|
}
|
|
28
|
|
|
|
|
29
|
|
|
/**
|
|
30
|
|
|
* Load fresh data.
|
|
31
|
|
|
* @param int|string $in
|
|
32
|
|
|
* @param bool $activeOnly
|
|
|
|
|
|
|
33
|
|
|
* @return IData
|
|
34
|
|
|
* @throws IdentificationNumberNotFoundException
|
|
35
|
|
|
*/
|
|
36
|
|
|
public function loadData($in)
|
|
37
|
|
|
{
|
|
38
|
|
|
try {
|
|
39
|
|
|
$this->loadXML((string) $in, TRUE);
|
|
40
|
|
|
} catch (IdentificationNumberNotFoundException $e) {
|
|
41
|
|
|
$this->loadXML((string) $in, FALSE);
|
|
42
|
|
|
}
|
|
43
|
|
|
return $this->getData();
|
|
44
|
|
|
}
|
|
45
|
|
|
|
|
46
|
|
|
/**
|
|
47
|
|
|
* Get temporary data.
|
|
48
|
|
|
* @return IData
|
|
49
|
|
|
*/
|
|
50
|
|
|
public function getData()
|
|
51
|
|
|
{
|
|
52
|
|
|
return $this->dataProvider->getData();
|
|
53
|
|
|
}
|
|
54
|
|
|
|
|
55
|
|
|
/**
|
|
56
|
|
|
* Load XML and fill Data object
|
|
57
|
|
|
* @param string $in
|
|
58
|
|
|
* @param bool $activeOnly
|
|
59
|
|
|
* @throws IdentificationNumberNotFoundException
|
|
60
|
|
|
*/
|
|
61
|
|
|
private function loadXML($in, $activeOnly)
|
|
62
|
|
|
{
|
|
63
|
|
|
$client = new GuzzleHttp\Client();
|
|
64
|
|
|
$xmlSource = $client->request('GET', $this->createUrl($in, $activeOnly))->getBody();
|
|
65
|
|
|
$xml = @simplexml_load_string($xmlSource);
|
|
66
|
|
|
if (!$xml) {
|
|
67
|
|
|
throw new IdentificationNumberNotFoundException($in);
|
|
68
|
|
|
}
|
|
69
|
|
|
|
|
70
|
|
|
$ns = $xml->getDocNamespaces();
|
|
71
|
|
|
$xmlEl = $xml->children($ns['are'])->children($ns['D'])->VBAS;
|
|
72
|
|
|
|
|
73
|
|
|
if (!isset($xmlEl->ICO)) {
|
|
74
|
|
|
throw new IdentificationNumberNotFoundException($in);
|
|
75
|
|
|
}
|
|
76
|
|
|
|
|
77
|
|
|
$this->processXml($xmlEl, $this->dataProvider->prepareData());
|
|
78
|
|
|
}
|
|
79
|
|
|
|
|
80
|
|
|
protected function processXml($xml, DataProvider $dataProvider)
|
|
81
|
|
|
{
|
|
82
|
|
|
$dataProvider->setIN($xml->ICO)
|
|
83
|
|
|
->setTIN($xml->DIC)
|
|
84
|
|
|
->setCity($xml->AA->N)
|
|
85
|
|
|
->setCompany($xml->OF)
|
|
86
|
|
|
->setStreet($xml->AD->UC, $xml->AA->NCO, isset($xml->AA->CO) ? $xml->AA->CO : NULL)
|
|
87
|
|
|
->setZip($xml->AA->PSC)
|
|
88
|
|
|
->setPerson($xml->PF->KPF)
|
|
89
|
|
|
->setCreated($xml->DV);
|
|
90
|
|
|
|
|
91
|
|
|
if (isset($xml->ROR)) {
|
|
92
|
|
|
$dataProvider->setActive($xml->ROR->SOR->SSU)
|
|
93
|
|
|
->setFileNumber($xml->ROR->SZ->OV)
|
|
94
|
|
|
->setCourt($xml->ROR->SZ->SD->T);
|
|
95
|
|
|
}
|
|
96
|
|
|
if ($this->activeMode === FALSE) {
|
|
97
|
|
|
$dataProvider->setActive(FALSE);
|
|
|
|
|
|
|
98
|
|
|
}
|
|
99
|
|
|
}
|
|
100
|
|
|
|
|
101
|
|
|
private function createUrl($inn, $activeOnly)
|
|
102
|
|
|
{
|
|
103
|
|
|
$this->activeMode = (bool) $activeOnly;
|
|
104
|
|
|
$parameters = [
|
|
105
|
|
|
'ico' => $inn,
|
|
106
|
|
|
'aktivni' => $activeOnly ? 'true' : 'false'
|
|
107
|
|
|
];
|
|
108
|
|
|
return self::URL . '?' . http_build_query($parameters);
|
|
109
|
|
|
}
|
|
110
|
|
|
|
|
111
|
|
|
private function createDataProvider()
|
|
112
|
|
|
{
|
|
113
|
|
|
return new DataProvider(new DataFactory());
|
|
114
|
|
|
}
|
|
115
|
|
|
|
|
116
|
|
|
}
|
|
117
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.