|
1
|
|
|
<?php namespace Arcanedev\GeoIP\Drivers; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\GeoIP\Contracts\GeoIPDriver; |
|
4
|
|
|
use Arcanedev\GeoIP\Location; |
|
5
|
|
|
use Illuminate\Support\Arr; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class AbstractDriver |
|
9
|
|
|
* |
|
10
|
|
|
* @package Arcanedev\GeoIP\Drivers |
|
11
|
|
|
* @author ARCANEDEV <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
abstract class AbstractDriver implements GeoIPDriver |
|
14
|
|
|
{ |
|
15
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
16
|
|
|
| Properties |
|
17
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
18
|
|
|
*/ |
|
19
|
|
|
/** |
|
20
|
|
|
* Driver options. |
|
21
|
|
|
* |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $options = []; |
|
25
|
|
|
|
|
26
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
27
|
|
|
| Constructor |
|
28
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
29
|
|
|
*/ |
|
30
|
|
|
/** |
|
31
|
|
|
* AbstractDriver constructor. |
|
32
|
|
|
* |
|
33
|
|
|
* @param array $options |
|
34
|
|
|
*/ |
|
35
|
90 |
|
public function __construct(array $options = []) |
|
36
|
|
|
{ |
|
37
|
90 |
|
$this->options = $options; |
|
38
|
90 |
|
$this->init(); |
|
39
|
90 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
42
|
|
|
| Main Functions |
|
43
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
44
|
|
|
*/ |
|
45
|
|
|
/** |
|
46
|
|
|
* Init the driver. |
|
47
|
|
|
*/ |
|
48
|
|
|
abstract protected function init(); |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Update the driver. |
|
52
|
|
|
* |
|
53
|
|
|
* @return bool |
|
54
|
|
|
* |
|
55
|
|
|
* @throws \Exception |
|
56
|
|
|
*/ |
|
57
|
|
|
public function update() |
|
58
|
|
|
{ |
|
59
|
|
|
// Do nothing |
|
60
|
|
|
|
|
61
|
|
|
return true; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
65
|
|
|
| Other Functions |
|
66
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
67
|
|
|
*/ |
|
68
|
|
|
/** |
|
69
|
|
|
* Get option value. |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $key |
|
72
|
|
|
* @param mixed $default |
|
73
|
|
|
* |
|
74
|
|
|
* @return mixed |
|
75
|
|
|
*/ |
|
76
|
36 |
|
protected function getOption($key, $default = null) |
|
77
|
|
|
{ |
|
78
|
36 |
|
return Arr::get($this->options, $key, $default); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Hydrate the location entity. |
|
83
|
|
|
* |
|
84
|
|
|
* @param array $attributes |
|
85
|
|
|
* |
|
86
|
|
|
* @return \Arcanedev\GeoIP\Location |
|
87
|
|
|
*/ |
|
88
|
24 |
|
protected function hydrate(array $attributes = []) |
|
89
|
|
|
{ |
|
90
|
24 |
|
return new Location($attributes); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|