6
6
7
7
class GeoIPLocation
8
8
{
9
+ protected $ config = null ;
10
+
9
11
protected $ ipLocated = false ;
10
12
11
13
protected $ ip = null ;
@@ -29,19 +31,27 @@ class GeoIPLocation
29
31
];
30
32
31
33
protected $ invalidIps = [
32
- '192.168.65.0 ' , ' ::1 ' , '127.0.0.1 '
34
+ '::1 ' , '127.0.0.1 ' , ' 192.168.65.0 '
33
35
];
34
36
35
37
protected $ localhostIp = '169.159.82.111 ' ;
36
38
37
- protected $ currency = 'NGN ' ;
39
+ protected $ baseCurrency = 'USD ' ;
38
40
39
- public function __construct ($ ip = null , $ currency = null )
41
+ public function __construct ($ config = [] )
40
42
{
41
- $ this ->ip = $ ip ;
42
- if ($ currency ) {
43
- $ this ->defaultCurrency = $ currency ;
44
- }
43
+
44
+ if (isset ($ config ['ip ' ])) {
45
+ $ this ->ip = $ config ['ip ' ];
46
+ }
47
+
48
+ if (isset ($ config ['baseCurrency ' ])) {
49
+ $ this ->baseCurrency = $ config ['baseCurrency ' ];
50
+ } else {
51
+ $ config ['baseCurrency ' ] = $ this ->baseCurrency ;
52
+ }
53
+
54
+ $ this ->config = $ config ;
45
55
}
46
56
47
57
protected function locate ()
@@ -50,15 +60,16 @@ protected function locate()
50
60
51
61
switch ($ default_web_service ) {
52
62
case 'ipinfo ' :
53
- $ webService = new IpInfoWebService ($ this ->getIP (), $ token );
63
+ $ token = null ;
64
+ $ webService = new IpInfoWebService ($ this ->getIP (), $ this ->config );
54
65
$ this ->geoData = $ webService ->locate ();
55
66
break ;
56
67
case 'geoplugin ' :
57
- $ webService = new GeoPluginWebService ($ this ->getIP (), $ this ->currency );
68
+ $ webService = new GeoPluginWebService ($ this ->getIP (), $ this ->config );
58
69
$ this ->geoData = $ webService ->locate ();
59
70
break ;
60
71
default :
61
- $ webService = new GeoPluginWebService ($ this ->getIP (), $ this ->currency );
72
+ $ webService = new GeoPluginWebService ($ this ->getIP (), $ this ->config );
62
73
$ this ->geoData = $ webService ->locate ();
63
74
break ;
64
75
}
0 commit comments