1 | <?php namespace Arcanedev\GeoIP; |
||
18 | class GeoIP implements GeoIPContract |
||
19 | { |
||
20 | /* ----------------------------------------------------------------- |
||
21 | | Properties |
||
22 | | ----------------------------------------------------------------- |
||
23 | */ |
||
24 | |||
25 | /** @var \Arcanedev\GeoIP\Contracts\GeoIPDriver */ |
||
26 | private $driver; |
||
27 | |||
28 | /** @var \Arcanedev\GeoIP\Contracts\GeoIPCache */ |
||
29 | private $cache; |
||
30 | |||
31 | /** @var array */ |
||
32 | protected $config = []; |
||
33 | |||
34 | /** @var \Arcanedev\GeoIP\Location */ |
||
35 | protected $location; |
||
36 | |||
37 | /** @var array */ |
||
38 | protected $defaultLocation = []; |
||
39 | |||
40 | /** @var string */ |
||
41 | protected $remoteIp; |
||
42 | |||
43 | /* ----------------------------------------------------------------- |
||
44 | | Constructor |
||
45 | | ----------------------------------------------------------------- |
||
46 | */ |
||
47 | |||
48 | /** |
||
49 | * Create a new GeoIP instance. |
||
50 | * |
||
51 | * @param \Arcanedev\GeoIP\Contracts\GeoIPDriver $driver |
||
52 | * @param \Arcanedev\GeoIP\Contracts\GeoIPCache $cache |
||
53 | * @param array $config |
||
54 | */ |
||
55 | 18 | public function __construct(GeoIPDriver $driver, GeoIPCache $cache, array $config) |
|
64 | |||
65 | /* ----------------------------------------------------------------- |
||
66 | | Getters & Setters |
||
67 | | ----------------------------------------------------------------- |
||
68 | */ |
||
69 | |||
70 | /** |
||
71 | * Get the GeoIP driver instance. |
||
72 | * |
||
73 | * @return \Arcanedev\GeoIP\Contracts\GeoIPDriver |
||
74 | */ |
||
75 | 9 | public function driver() |
|
79 | |||
80 | /** |
||
81 | * Get cache instance. |
||
82 | * |
||
83 | * @return \Arcanedev\GeoIP\Contracts\GeoIPCache |
||
84 | */ |
||
85 | 9 | public function cache() |
|
89 | |||
90 | /** |
||
91 | * Get configuration value. |
||
92 | * |
||
93 | * @param string $key |
||
94 | * @param mixed $default |
||
95 | * |
||
96 | * @return mixed |
||
97 | */ |
||
98 | 18 | private function config($key, $default = null) |
|
102 | |||
103 | /** |
||
104 | * Set the default location. |
||
105 | * |
||
106 | * @param array $location |
||
107 | * |
||
108 | * @return self |
||
109 | */ |
||
110 | 18 | public function setDefaultLocation(array $location) |
|
116 | |||
117 | /** |
||
118 | * Get the currency code from ISO. |
||
119 | * |
||
120 | * @param string $iso |
||
121 | * |
||
122 | * @return string |
||
123 | */ |
||
124 | 6 | public function getCurrency($iso) |
|
130 | |||
131 | /* ----------------------------------------------------------------- |
||
132 | | Main Methods |
||
133 | | ----------------------------------------------------------------- |
||
134 | */ |
||
135 | |||
136 | /** |
||
137 | * Get the location from the provided IP. |
||
138 | * |
||
139 | * @param string $ipAddress |
||
140 | * |
||
141 | * @return \Arcanedev\GeoIP\Location |
||
142 | */ |
||
143 | 6 | public function location($ipAddress = null) |
|
153 | |||
154 | /** |
||
155 | * Find location from IP. |
||
156 | * |
||
157 | * @param string $ip |
||
158 | * |
||
159 | * @return \Arcanedev\GeoIP\Location |
||
160 | * |
||
161 | * @throws \Exception |
||
162 | */ |
||
163 | 6 | private function find($ip = null) |
|
192 | |||
193 | /** |
||
194 | * Determine if the location should be cached. |
||
195 | * |
||
196 | * @param string|null $ipAddress |
||
197 | * @param \Arcanedev\GeoIP\Location $location |
||
198 | * |
||
199 | * @return bool |
||
200 | */ |
||
201 | 6 | private function shouldCache($ipAddress = null, Location $location) |
|
217 | } |
||
218 |