|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DucCnzj\Ip; |
|
4
|
|
|
|
|
5
|
|
|
use DucCnzj\Ip\Imp\DataMapImp; |
|
6
|
|
|
use DucCnzj\Ip\Exceptions\MethodNotExistException; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* |
|
10
|
|
|
* Class NullDataMapper |
|
11
|
|
|
* |
|
12
|
|
|
* @package DucCnzj\Ip |
|
13
|
|
|
*/ |
|
14
|
|
|
class NullDataMapper implements DataMapImp |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var array |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $info = []; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param array $info |
|
23
|
|
|
* |
|
24
|
|
|
* @return DataMapImp |
|
25
|
|
|
* |
|
26
|
|
|
* @author duc <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
5 |
|
public function setInfo(array $info): DataMapImp |
|
29
|
|
|
{ |
|
30
|
5 |
|
$this->info = $info; |
|
31
|
|
|
|
|
32
|
5 |
|
return $this; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return string|null |
|
37
|
|
|
* |
|
38
|
|
|
* @author duc <[email protected]> |
|
39
|
|
|
*/ |
|
40
|
1 |
|
public function getIp() |
|
41
|
|
|
{ |
|
42
|
1 |
|
return isset($this->info['ip']) ? $this->info['ip'] : null; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return null |
|
47
|
|
|
* |
|
48
|
|
|
* @author duc <[email protected]> |
|
49
|
|
|
*/ |
|
50
|
4 |
|
public function getCity() |
|
51
|
|
|
{ |
|
52
|
4 |
|
return null; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return null |
|
57
|
|
|
* |
|
58
|
|
|
* @author duc <[email protected]> |
|
59
|
|
|
*/ |
|
60
|
1 |
|
public function getCountry() |
|
61
|
|
|
{ |
|
62
|
1 |
|
return null; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return null |
|
67
|
|
|
* |
|
68
|
|
|
* @author duc <[email protected]> |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function getRegion() |
|
71
|
|
|
{ |
|
72
|
1 |
|
return null; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return null |
|
77
|
|
|
* |
|
78
|
|
|
* @author duc <[email protected]> |
|
79
|
|
|
*/ |
|
80
|
2 |
|
public function getAddress() |
|
81
|
|
|
{ |
|
82
|
2 |
|
return null; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param string $name |
|
87
|
|
|
* |
|
88
|
|
|
* @return mixed|null |
|
89
|
|
|
* |
|
90
|
|
|
* @author duc <[email protected]> |
|
91
|
|
|
*/ |
|
92
|
1 |
|
public function __get(string $name) |
|
93
|
|
|
{ |
|
94
|
1 |
|
$field = toUnderScore($name); |
|
95
|
|
|
|
|
96
|
1 |
|
return isset($this->info[$field]) ? $this->info[$field] : null; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param string $name |
|
101
|
|
|
* @param mixed $arguments |
|
102
|
|
|
* |
|
103
|
|
|
* @return mixed|string |
|
104
|
|
|
* @throws MethodNotExistException |
|
105
|
|
|
* |
|
106
|
|
|
* @author duc <[email protected]> |
|
107
|
|
|
*/ |
|
108
|
3 |
|
public function __call(string $name, $arguments) |
|
109
|
|
|
{ |
|
110
|
3 |
|
preg_match('/get(.*)/', $name, $matches, PREG_OFFSET_CAPTURE); |
|
111
|
|
|
|
|
112
|
3 |
|
if (count($matches) >= 2 && strlen($name) > 3) { |
|
113
|
2 |
|
$field = toUnderScore($matches[1][0]); |
|
114
|
|
|
|
|
115
|
2 |
|
return isset($this->info[$field]) ? $this->info[$field] : null; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
1 |
|
throw new MethodNotExistException("{$name} 方法不存在"); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return bool |
|
123
|
|
|
* |
|
124
|
|
|
* @author duc <[email protected]> |
|
125
|
|
|
*/ |
|
126
|
1 |
|
public function hasInfo(): bool |
|
127
|
|
|
{ |
|
128
|
1 |
|
return false; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|