1
|
|
|
<?php namespace Arcanedev\GeoIP; |
2
|
|
|
|
3
|
|
|
use Arcanedev\GeoIP\Contracts\DriverFactory; |
4
|
|
|
use Arcanedev\Support\Manager; |
5
|
|
|
use Illuminate\Contracts\Foundation\Application; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class DriverManager |
9
|
|
|
* |
10
|
|
|
* @package Arcanedev\GeoIP |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class DriverManager extends Manager implements DriverFactory |
14
|
|
|
{ |
15
|
|
|
/* ------------------------------------------------------------------------------------------------ |
16
|
|
|
| Constructor |
17
|
|
|
| ------------------------------------------------------------------------------------------------ |
18
|
|
|
*/ |
19
|
|
|
/** |
20
|
|
|
* DriverManager constructor. |
21
|
|
|
* |
22
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
23
|
|
|
*/ |
24
|
96 |
|
public function __construct(Application $app) |
25
|
|
|
{ |
26
|
96 |
|
parent::__construct($app); |
|
|
|
|
27
|
96 |
|
} |
28
|
|
|
|
29
|
|
|
/* ------------------------------------------------------------------------------------------------ |
30
|
|
|
| Getters & Setters |
31
|
|
|
| ------------------------------------------------------------------------------------------------ |
32
|
|
|
*/ |
33
|
|
|
/** |
34
|
|
|
* Get the default driver name. |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
42 |
|
public function getDefaultDriver() |
39
|
|
|
{ |
40
|
42 |
|
return $this->getConfig('default'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the driver class. |
45
|
|
|
* |
46
|
|
|
* @param string $key |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
90 |
|
private function getDriverClass($key) |
51
|
|
|
{ |
52
|
90 |
|
return $this->getConfig("supported.$key.driver"); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get the driver options. |
57
|
|
|
* |
58
|
|
|
* @param string $key |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
90 |
|
private function getDriverOptions($key) |
63
|
|
|
{ |
64
|
90 |
|
return $this->getConfig("supported.$key.options", []); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get the config. |
69
|
|
|
* |
70
|
|
|
* @param string $key |
71
|
|
|
* @param mixed|null $default |
72
|
|
|
* |
73
|
|
|
* @return mixed |
74
|
|
|
*/ |
75
|
90 |
|
public function getConfig($key, $default = null) |
76
|
|
|
{ |
77
|
90 |
|
return $this->config()->get("geoip.$key", $default); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get the config instance. |
82
|
|
|
* |
83
|
|
|
* @return \Illuminate\Contracts\Config\Repository |
84
|
|
|
*/ |
85
|
90 |
|
private function config() |
86
|
|
|
{ |
87
|
90 |
|
return $this->app['config']; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/* ------------------------------------------------------------------------------------------------ |
91
|
|
|
| Main Functions |
92
|
|
|
| ------------------------------------------------------------------------------------------------ |
93
|
|
|
*/ |
94
|
|
|
/** |
95
|
|
|
* Build the 'ip-api' driver. |
96
|
|
|
* |
97
|
|
|
* @return Drivers\IpApiDriver |
98
|
|
|
*/ |
99
|
18 |
|
protected function createIpApiDriver() |
100
|
|
|
{ |
101
|
18 |
|
return $this->buildDriver('ip-api'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Build the 'freegeoip' driver. |
106
|
|
|
* |
107
|
|
|
* @return Drivers\FreeGeoIpDriver |
108
|
|
|
*/ |
109
|
60 |
|
protected function createFreegeoipDriver() |
110
|
|
|
{ |
111
|
60 |
|
return $this->buildDriver('freegeoip'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get the 'maxmind-database' driver. |
116
|
|
|
* |
117
|
|
|
* @return mixed |
118
|
|
|
*/ |
119
|
24 |
|
protected function createMaxmindDatabaseDriver() |
120
|
|
|
{ |
121
|
24 |
|
return $this->buildDriver('maxmind-database'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get the 'maxmind-api' driver. |
126
|
|
|
* |
127
|
|
|
* @return Drivers\MaxmindApiDriver |
128
|
|
|
*/ |
129
|
6 |
|
protected function createMaxmindApiDriver() |
130
|
|
|
{ |
131
|
6 |
|
return $this->buildDriver('maxmind-api'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/* ------------------------------------------------------------------------------------------------ |
135
|
|
|
| Other Functions |
136
|
|
|
| ------------------------------------------------------------------------------------------------ |
137
|
|
|
*/ |
138
|
|
|
/** |
139
|
|
|
* Build the driver. |
140
|
|
|
* |
141
|
|
|
* @param string $key |
142
|
|
|
* |
143
|
|
|
* @return mixed |
144
|
|
|
*/ |
145
|
90 |
|
private function buildDriver($key) |
146
|
|
|
{ |
147
|
90 |
|
$class = $this->getDriverClass($key); |
148
|
|
|
|
149
|
90 |
|
return new $class($this->getDriverOptions($key)); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: