forked from EdgedesignCZ/ares
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ares.php
60 lines (48 loc) · 1.25 KB
/
Ares.php
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
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Edge\Ares;
use Edge\Ares\Container\Address;
use Edge\Ares\Exception\InvalidArgumentException;
use Edge\Ares\Parser\ParserInterface;
use Edge\Ares\Provider\ProviderInterface;
/**
*
* @author Marek Makovec <[email protected]>
*/
class Ares
{
const ARES_API_URL = 'http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_bas.cgi?ico=%s';
private $parser;
private $provider;
public function __construct(ParserInterface $parser, ProviderInterface $provider)
{
$this->parser = $parser;
$this->provider = $provider;
}
/**
* @param int $ic
*
* @return Address
*
* @throws \Edge\Ares\Exception\ExceptionInterface
*/
public function fetchSubjectAddress($ic)
{
$ic = (int) $ic;
$this->assertIc($ic);
$xml = $this->provider->fetchSubjectXml($ic);
return $this->parser->parseAddress($xml);
}
/**
* This method asserts that given IC is valid. If not, InvalidArgumentException is thrown.
*
* @param int $ic
*
* @throws \Edge\Ares\Exception\InvalidArgumentException
*/
private function assertIc($ic)
{
if (!$ic) {
throw new InvalidArgumentException('Given IC is not valid.');
}
}
}