|
1
|
|
|
<?php namespace Arcanedev\GeoIP; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\GeoIP\Contracts\DriverFactory; |
|
4
|
|
|
use Illuminate\Support\Manager; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class DriverManager |
|
8
|
|
|
* |
|
9
|
|
|
* @package Arcanedev\GeoIP |
|
10
|
|
|
* @author ARCANEDEV <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class DriverManager extends Manager implements DriverFactory |
|
13
|
|
|
{ |
|
14
|
|
|
/* ----------------------------------------------------------------- |
|
15
|
|
|
| Getters & Setters |
|
16
|
|
|
| ----------------------------------------------------------------- |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Get the default driver name. |
|
21
|
|
|
* |
|
22
|
|
|
* @return string |
|
23
|
|
|
*/ |
|
24
|
21 |
|
public function getDefaultDriver() |
|
25
|
|
|
{ |
|
26
|
21 |
|
return $this->config()->get("geoip.default"); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Get the config instance. |
|
31
|
|
|
* |
|
32
|
|
|
* @return \Illuminate\Contracts\Config\Repository |
|
33
|
|
|
*/ |
|
34
|
45 |
|
private function config() |
|
35
|
|
|
{ |
|
36
|
45 |
|
return $this->app['config']; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/* ----------------------------------------------------------------- |
|
40
|
|
|
| Main Methods |
|
41
|
|
|
| ----------------------------------------------------------------- |
|
42
|
|
|
*/ |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Build the 'ip-api' driver. |
|
46
|
|
|
* |
|
47
|
|
|
* @return \Arcanedev\GeoIP\Drivers\AbstractDriver |
|
48
|
|
|
*/ |
|
49
|
9 |
|
protected function createIpApiDriver() |
|
50
|
|
|
{ |
|
51
|
9 |
|
return $this->buildDriver('ip-api'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Build the 'freegeoip' driver. |
|
56
|
|
|
* |
|
57
|
|
|
* @return \Arcanedev\GeoIP\Drivers\AbstractDriver |
|
58
|
|
|
*/ |
|
59
|
30 |
|
protected function createFreegeoipDriver() |
|
60
|
|
|
{ |
|
61
|
30 |
|
return $this->buildDriver('freegeoip'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the 'maxmind-database' driver. |
|
66
|
|
|
* |
|
67
|
|
|
* @return \Arcanedev\GeoIP\Drivers\AbstractDriver |
|
68
|
|
|
*/ |
|
69
|
12 |
|
protected function createMaxmindDatabaseDriver() |
|
70
|
|
|
{ |
|
71
|
12 |
|
return $this->buildDriver('maxmind-database'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the 'maxmind-api' driver. |
|
76
|
|
|
* |
|
77
|
|
|
* @return \Arcanedev\GeoIP\Drivers\AbstractDriver |
|
78
|
|
|
*/ |
|
79
|
3 |
|
protected function createMaxmindApiDriver() |
|
80
|
|
|
{ |
|
81
|
3 |
|
return $this->buildDriver('maxmind-api'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/* ----------------------------------------------------------------- |
|
85
|
|
|
| Other Methods |
|
86
|
|
|
| ----------------------------------------------------------------- |
|
87
|
|
|
*/ |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Build the driver. |
|
91
|
|
|
* |
|
92
|
|
|
* @param string $name |
|
93
|
|
|
* |
|
94
|
|
|
* @return \Arcanedev\GeoIP\Drivers\AbstractDriver |
|
95
|
|
|
*/ |
|
96
|
45 |
|
private function buildDriver($name) |
|
97
|
|
|
{ |
|
98
|
45 |
|
$class = $this->config()->get("geoip.drivers.$name.driver"); |
|
99
|
|
|
|
|
100
|
45 |
|
return new $class( |
|
101
|
45 |
|
$this->config()->get("geoip.drivers.$name.options", []) |
|
102
|
|
|
); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|