|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Geotools library. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Antoine Corcy <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace League\Geotools\CLI\Command\Geocoder; |
|
13
|
|
|
|
|
14
|
|
|
use Psr\Cache\CacheItemPoolInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Command class |
|
18
|
|
|
* |
|
19
|
|
|
* @author Antoine Corcy <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Command extends \Symfony\Component\Console\Command\Command |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Available providers. |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
private $providers = [ |
|
29
|
|
|
'free_geo_ip' => 'FreeGeoIp', |
|
30
|
|
|
'host_ip' => 'HostIp', |
|
31
|
|
|
'ip_info_db' => 'IpInfoDb', |
|
32
|
|
|
'google_maps' => 'GoogleMaps', |
|
33
|
|
|
'google_maps_business' => 'GoogleMapsBusiness', |
|
34
|
|
|
'bing_maps' => 'BingMaps', |
|
35
|
|
|
'openstreetmaps' => 'OpenStreetMap', |
|
36
|
|
|
'cloudmade' => 'CloudMade', |
|
37
|
|
|
'geoip' => 'Geoip', |
|
38
|
|
|
'map_quest' => 'MapQuest', |
|
39
|
|
|
'oio_rest' => 'OIORest', |
|
40
|
|
|
'geocoder_ca' => 'GeocoderCa', |
|
41
|
|
|
'geocoder_us' => 'GeocoderUs', |
|
42
|
|
|
'ign_openls' => 'IGNOpenLS', |
|
43
|
|
|
'data_science_toolkit' => 'DataScienceToolkit', |
|
44
|
|
|
'yandex' => 'Yandex', |
|
45
|
|
|
'geo_plugin' => 'GeoPlugin', |
|
46
|
|
|
'geo_ips' => 'GeoIPs', |
|
47
|
|
|
'maxmind' => 'MaxMind', |
|
48
|
|
|
'geonames' => 'Geonames', |
|
49
|
|
|
'ip_geo_base' => 'IpGeoBase', |
|
50
|
|
|
'baidu' => 'Baidu', |
|
51
|
|
|
'tomtom' => 'TomTom', |
|
52
|
|
|
'arcgis_online' => 'ArcGISOnline', |
|
53
|
|
|
]; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Available dumpers. |
|
57
|
|
|
* |
|
58
|
|
|
* @var array |
|
59
|
|
|
*/ |
|
60
|
|
|
private $dumpers = [ |
|
61
|
|
|
'gpx' => 'Gpx', |
|
62
|
|
|
'geojson' => 'GeoJson', |
|
63
|
|
|
'kml' => 'Kml', |
|
64
|
|
|
'wkb' => 'Wkb', |
|
65
|
|
|
'wkt' => 'Wkt', |
|
66
|
|
|
]; |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param string $factoryCallable |
|
71
|
|
|
* |
|
72
|
|
|
* @return CacheItemPoolInterface |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function getCache($factoryCallable) |
|
75
|
|
|
{ |
|
76
|
|
|
$factoryCallable = $this->lowerize((trim($factoryCallable))); |
|
77
|
|
|
if (!is_callable($factoryCallable)) { |
|
78
|
|
|
throw new \LogicException(sprintf('Cache must be called with a valid callable on the format "Example\Acme::create". "%s" given.', $factoryCallable)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$psr6 = call_user_func($factoryCallable); |
|
82
|
|
|
if (!$psr6 instanceof CacheItemPoolInterface) { |
|
83
|
|
|
throw new \LogicException('Return value of factory callable must be a CacheItemPoolInterface'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $psr6; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Returns the provider class name. |
|
91
|
|
|
* The default provider is Google Maps. |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $provider The name of the provider to use. |
|
94
|
|
|
* |
|
95
|
|
|
* @return string The name of the provider class to use. |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function getProvider($provider) |
|
98
|
|
|
{ |
|
99
|
|
|
$provider = $this->lowerize((trim($provider))); |
|
100
|
|
|
$provider = array_key_exists($provider, $this->providers) |
|
101
|
|
|
? $this->providers[$provider] |
|
102
|
|
|
: $this->providers['google_maps']; |
|
103
|
|
|
|
|
104
|
|
|
return '\\Geocoder\\Provider\\' . $provider . $provider; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Returns the list of available providers sorted by alphabetical order. |
|
109
|
|
|
* |
|
110
|
|
|
* @return string The list of available providers comma separated. |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function getProviders() |
|
113
|
|
|
{ |
|
114
|
|
|
ksort($this->providers); |
|
115
|
|
|
|
|
116
|
|
|
return implode(', ', array_keys($this->providers)); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Returns the dumper class name. |
|
121
|
|
|
* The default dumper is WktDumper. |
|
122
|
|
|
* |
|
123
|
|
|
* @param string $dumper The name of the dumper to use. |
|
124
|
|
|
* |
|
125
|
3 |
|
* @return string The name of the dumper class to use. |
|
126
|
|
|
*/ |
|
127
|
3 |
|
protected function getDumper($dumper) |
|
128
|
|
|
{ |
|
129
|
3 |
|
$dumper = $this->lowerize((trim($dumper))); |
|
130
|
|
|
$dumper = array_key_exists($dumper, $this->dumpers) |
|
131
|
|
|
? $this->dumpers[$dumper] |
|
132
|
|
|
: $this->dumpers['wkt']; |
|
133
|
|
|
|
|
134
|
|
|
return '\\Geocoder\\Dumper\\' . $dumper; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Returns the list of available dumpers sorted by alphabetical order. |
|
139
|
|
|
* |
|
140
|
|
|
* @return string The list of available dumpers comma separated. |
|
141
|
|
|
*/ |
|
142
|
|
|
protected function getDumpers() |
|
143
|
|
|
{ |
|
144
|
|
|
ksort($this->dumpers); |
|
145
|
|
|
|
|
146
|
|
|
return implode(', ', array_keys($this->dumpers)); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Make a string lowercase. |
|
151
|
|
|
* |
|
152
|
|
|
* @param string $string A string to lowercase. |
|
153
|
|
|
* |
|
154
|
|
|
* @return string The lowercased string. |
|
155
|
3 |
|
*/ |
|
156
|
|
|
private function lowerize($string) |
|
157
|
3 |
|
{ |
|
158
|
|
|
return extension_loaded('mbstring') ? mb_strtolower($string, 'UTF-8') : strtolower($string); |
|
159
|
3 |
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|