|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace IpInfo\Lib; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class IpinfoResponse |
|
9
|
|
|
* |
|
10
|
|
|
* @package IpInfo\Lib |
|
11
|
|
|
*/ |
|
12
|
|
|
class IpinfoResponse |
|
13
|
|
|
{ |
|
14
|
|
|
const IP = 'ip'; |
|
15
|
|
|
const HOSTNAME = 'hostname'; |
|
16
|
|
|
const LOC = 'loc'; |
|
17
|
|
|
const ORG = 'org'; |
|
18
|
|
|
const CITY = 'city'; |
|
19
|
|
|
const REGION = 'region'; |
|
20
|
|
|
const COUNTRY = 'country'; |
|
21
|
|
|
const PHONE = 'phone'; |
|
22
|
|
|
const POSTAL = 'postal'; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Contains all the properties of the host. |
|
27
|
|
|
* |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $properties; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Contains the status code ipInfo http response. |
|
34
|
|
|
* @var integer |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $statusCode; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Create an IpinfoResponse object with all the properties. |
|
40
|
|
|
* |
|
41
|
|
|
* @param JsonResponse $response |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(JsonResponse $response) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->statusCode = $response->getStatusCode(); |
|
46
|
|
|
|
|
47
|
|
|
$properties = json_decode($response->getContent(), true); |
|
48
|
|
|
//Merge default values |
|
49
|
|
|
$this->properties = array_merge(array( |
|
50
|
|
|
static::CITY => '', |
|
51
|
|
|
static::COUNTRY => '', |
|
52
|
|
|
static::HOSTNAME => '', |
|
53
|
|
|
static::IP => '', |
|
54
|
|
|
static::LOC => '', |
|
55
|
|
|
static::ORG => '', |
|
56
|
|
|
static::PHONE => '', |
|
57
|
|
|
static::POSTAL => '', |
|
58
|
|
|
static::REGION => '', |
|
59
|
|
|
), $properties); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get the city value. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getCity() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->properties[static::CITY]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get the country value. |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getCountry() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->properties[static::COUNTRY]; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Get the hostname value. |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getHostname() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->properties[static::HOSTNAME]; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get the ip value. |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getIp() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->properties[static::IP]; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get the loc value. |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getLoc() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->properties[static::LOC]; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Get the org value. |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getOrg() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->properties[static::ORG]; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Get the phone value. |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getPhone() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->properties[static::PHONE]; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Get the postal value. |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getPostal() |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->properties[static::POSTAL]; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Get the region value. |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getRegion() |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->properties[static::REGION]; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Get all the properties. |
|
136
|
|
|
* |
|
137
|
|
|
* @return array An associative array with all the properties. |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getProperties() |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->properties; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Get the status code ipinfo response. |
|
146
|
|
|
* |
|
147
|
|
|
* @return integer |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getStatusCode() |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->statusCode; |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|