1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CodeblogPro\GeoLocation\Application\GeoIpRemoteServices; |
4
|
|
|
|
5
|
|
|
class GeoIpRemoteServices |
6
|
|
|
{ |
7
|
|
|
private static $instance = null; |
8
|
|
|
private array $sortToServicesMap = []; |
|
|
|
|
9
|
|
|
|
10
|
|
|
private function __construct() |
11
|
|
|
{ |
12
|
|
|
$this->initServicesMap(); |
13
|
|
|
$this->sortServicesMap(); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public static function getInstance() |
17
|
|
|
{ |
18
|
|
|
if (is_null(self::$instance)) { |
19
|
|
|
self::$instance = new self(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
return self::$instance; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getSortedToServicesMap(): array |
26
|
|
|
{ |
27
|
|
|
return $this->sortToServicesMap; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getSortedServices(): array |
31
|
|
|
{ |
32
|
|
|
$services = []; |
33
|
|
|
|
34
|
|
|
foreach ($this->sortToServicesMap as $remoteServiceSort => $remoteServices) { |
35
|
|
|
foreach ($remoteServices as $remoteService) { |
36
|
|
|
$services[] = $remoteService; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $services; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function __clone() |
44
|
|
|
{ |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private function initServicesMap() |
48
|
|
|
{ |
49
|
|
|
$daDataOptions = new DaDataOptions(); |
50
|
|
|
|
51
|
|
|
if ($daDataOptions->isEnabled()) { |
52
|
|
|
$daData = new DaData($daDataOptions); |
53
|
|
|
$this->sortToServicesMap[$daDataOptions->getSort()][] = $daData; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$sypexGeoOptions = new SypexGeoOptions(); |
57
|
|
|
|
58
|
|
|
if ($sypexGeoOptions->isEnabled()) { |
59
|
|
|
$sypexGeo = new SypexGeo($sypexGeoOptions); |
60
|
|
|
$this->sortToServicesMap[$sypexGeoOptions->getSort()][] = $sypexGeo; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$maxMindOptions = new MaxMindOptions(); |
64
|
|
|
|
65
|
|
|
if ($maxMindOptions->isEnabled()) { |
66
|
|
|
$maxMind = new MaxMind($maxMindOptions); |
67
|
|
|
$this->sortToServicesMap[$maxMindOptions->getSort()][] = $maxMind; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function sortServicesMap() |
72
|
|
|
{ |
73
|
|
|
ksort($this->sortToServicesMap); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|