1 | <?php namespace Arcanedev\GeoIP; |
||
18 | class GeoIP implements GeoIPContract |
||
19 | { |
||
20 | /* ------------------------------------------------------------------------------------------------ |
||
21 | | Properties |
||
22 | | ------------------------------------------------------------------------------------------------ |
||
23 | */ |
||
24 | /** @var \Arcanedev\GeoIP\Contracts\GeoIPDriver */ |
||
25 | private $driver; |
||
26 | |||
27 | /** @var \Arcanedev\GeoIP\Contracts\GeoIPCache */ |
||
28 | private $cache; |
||
29 | |||
30 | /** @var array */ |
||
31 | protected $config = []; |
||
32 | |||
33 | /** @var \Arcanedev\GeoIP\Location */ |
||
34 | protected $location; |
||
35 | |||
36 | /** @var array */ |
||
37 | protected $defaultLocation = []; |
||
38 | |||
39 | /** @var string */ |
||
40 | protected $remoteIp; |
||
41 | |||
42 | /* ------------------------------------------------------------------------------------------------ |
||
43 | | Constructor |
||
44 | | ------------------------------------------------------------------------------------------------ |
||
45 | */ |
||
46 | /** |
||
47 | * Create a new GeoIP instance. |
||
48 | * |
||
49 | * @param \Arcanedev\GeoIP\Contracts\GeoIPDriver $driver |
||
50 | * @param \Arcanedev\GeoIP\Contracts\GeoIPCache $cache |
||
51 | * @param array $config |
||
52 | */ |
||
53 | 36 | public function __construct(GeoIPDriver $driver, GeoIPCache $cache, array $config) |
|
62 | |||
63 | /* ------------------------------------------------------------------------------------------------ |
||
64 | | Getters & Setters |
||
65 | | ------------------------------------------------------------------------------------------------ |
||
66 | */ |
||
67 | /** |
||
68 | * Get the GeoIP driver instance. |
||
69 | * |
||
70 | * @return \Arcanedev\GeoIP\Contracts\GeoIPDriver |
||
71 | */ |
||
72 | 18 | public function driver() |
|
76 | |||
77 | /** |
||
78 | * Get cache instance. |
||
79 | * |
||
80 | * @return \Arcanedev\GeoIP\Contracts\GeoIPCache |
||
81 | */ |
||
82 | 18 | public function cache() |
|
86 | |||
87 | /** |
||
88 | * Get configuration value. |
||
89 | * |
||
90 | * @param string $key |
||
91 | * @param mixed $default |
||
92 | * |
||
93 | * @return mixed |
||
94 | */ |
||
95 | 36 | private function config($key, $default = null) |
|
99 | |||
100 | /** |
||
101 | * Set the default location. |
||
102 | * |
||
103 | * @param array $location |
||
104 | * |
||
105 | * @return self |
||
106 | */ |
||
107 | 36 | public function setDefaultLocation(array $location) |
|
113 | |||
114 | /** |
||
115 | * Get the currency code from ISO. |
||
116 | * |
||
117 | * @param string $iso |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | 12 | public function getCurrency($iso) |
|
127 | |||
128 | /* ------------------------------------------------------------------------------------------------ |
||
129 | | Main Functions |
||
130 | | ------------------------------------------------------------------------------------------------ |
||
131 | */ |
||
132 | /** |
||
133 | * Get the location from the provided IP. |
||
134 | * |
||
135 | * @param string $ipAddress |
||
136 | * |
||
137 | * @return \Arcanedev\GeoIP\Location |
||
138 | */ |
||
139 | 12 | public function location($ipAddress = null) |
|
149 | |||
150 | /** |
||
151 | * Find location from IP. |
||
152 | * |
||
153 | * @param string $ip |
||
154 | * |
||
155 | * @return \Arcanedev\GeoIP\Location |
||
156 | * |
||
157 | * @throws \Exception |
||
158 | */ |
||
159 | 12 | private function find($ip = null) |
|
188 | |||
189 | /** |
||
190 | * Determine if the location should be cached. |
||
191 | * |
||
192 | * @param string|null $ipAddress |
||
193 | * @param \Arcanedev\GeoIP\Location $location |
||
194 | * |
||
195 | * @return bool |
||
196 | */ |
||
197 | 12 | private function shouldCache($ipAddress = null, Location $location) |
|
213 | } |
||
214 |