1 | <?php namespace Arcanedev\LaravelTracker\Detectors; |
||
12 | class GeoIpDetector implements GeoIpDetectorContract |
||
13 | { |
||
14 | /* ------------------------------------------------------------------------------------------------ |
||
15 | | Properties |
||
16 | | ------------------------------------------------------------------------------------------------ |
||
17 | */ |
||
18 | /** |
||
19 | * @var \Arcanedev\GeoIP\Contracts\GeoIP |
||
20 | */ |
||
21 | private $geoip; |
||
22 | |||
23 | /* ------------------------------------------------------------------------------------------------ |
||
24 | | Constructor |
||
25 | | ------------------------------------------------------------------------------------------------ |
||
26 | */ |
||
27 | 18 | public function __construct(GeoIP $geoip) |
|
28 | { |
||
29 | 18 | $this->geoip = $geoip; |
|
30 | 18 | } |
|
31 | |||
32 | /* ------------------------------------------------------------------------------------------------ |
||
33 | | Main Functions |
||
34 | | ------------------------------------------------------------------------------------------------ |
||
35 | */ |
||
36 | /** |
||
37 | * Get the geoip data. |
||
38 | * |
||
39 | * @param string $ipAddress |
||
40 | * |
||
41 | * @return array|null |
||
42 | */ |
||
43 | 18 | public function search($ipAddress) |
|
44 | { |
||
45 | try { |
||
46 | 18 | if ($location = $this->geoip->location($ipAddress)) { |
|
47 | 18 | return $this->renderData($location); |
|
48 | } |
||
49 | } |
||
50 | catch (\Exception $e) { |
||
51 | // do nothing |
||
52 | } |
||
53 | |||
54 | return null; |
||
55 | } |
||
56 | |||
57 | /* ------------------------------------------------------------------------------------------------ |
||
58 | | Other Functions |
||
59 | | ------------------------------------------------------------------------------------------------ |
||
60 | */ |
||
61 | /** |
||
62 | * Render the data. |
||
63 | * |
||
64 | * @param \Arcanedev\GeoIP\Location $location |
||
65 | * |
||
66 | * @return array |
||
67 | */ |
||
68 | 18 | private function renderData($location) |
|
84 | } |
||
85 |