|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DominionEnterprises\NetAcuity; |
|
4
|
|
|
|
|
5
|
|
|
use DominionEnterprises\NetAcuity\Databases\NetAcuityDatabaseInterface; |
|
6
|
|
|
use DominionEnterprises\Util; |
|
7
|
|
|
use Exception; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* A client to access a NetAcuity server for geo-ip lookup. |
|
11
|
|
|
*/ |
|
12
|
|
|
final class NetAcuity |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var NetAcuityDatabaseInterface The Net Acuity Database to fetch data from. |
|
16
|
|
|
*/ |
|
17
|
|
|
private $_database; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Create the NetAcuity client. |
|
21
|
|
|
* |
|
22
|
|
|
* @param NetAcuityDatabaseInterface $database The Net Acuity Database to be used. |
|
23
|
|
|
* |
|
24
|
|
|
* @throws Exception |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(NetAcuityDatabaseInterface $database) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->_database = $database; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Gets the geo data for the given IP. |
|
33
|
|
|
* |
|
34
|
|
|
* Failures will be raised as exceptions. |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $ip The ip address to lookup |
|
37
|
|
|
* |
|
38
|
|
|
* @return array { |
|
39
|
|
|
* @type string $country |
|
40
|
|
|
* @type string $region |
|
41
|
|
|
* @type string $city |
|
42
|
|
|
* @type string $conn-speed |
|
43
|
|
|
* @type string $metro-code |
|
44
|
|
|
* @type string $latitude |
|
45
|
|
|
* @type string $longitude |
|
46
|
|
|
* @type string $postal-code |
|
47
|
|
|
* @type string $country-code |
|
48
|
|
|
* @type string $region-code |
|
49
|
|
|
* @type string $city-code |
|
50
|
|
|
* @type string $continent-code |
|
51
|
|
|
* @type string $two-letter-country |
|
52
|
|
|
* @type string $area-code |
|
53
|
|
|
* @type string $country-conf |
|
54
|
|
|
* @type string $region-conf |
|
55
|
|
|
* @type string $city-conf |
|
56
|
|
|
* @type string $postal-conf |
|
57
|
|
|
* @type string $gmt-offset |
|
58
|
|
|
* @type string $in-dist |
|
59
|
|
|
* @type string $timezone-name |
|
60
|
|
|
* } |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getGeo(string $ip) |
|
63
|
|
|
{ |
|
64
|
|
|
Util::throwIfNotType(['string' => $ip], true); |
|
65
|
|
|
return $this->_database->fetch($ip); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|