|
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
|
|
|
/** |
|
15
|
|
|
* Command class |
|
16
|
|
|
* |
|
17
|
|
|
* @author Antoine Corcy <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class Command extends \Symfony\Component\Console\Command\Command |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Available caches. |
|
23
|
|
|
* |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
private $caches = [ |
|
27
|
|
|
'memcached' => 'Memcached', |
|
28
|
|
|
'mongodb' => 'MongoDB', |
|
29
|
|
|
'redis' => 'Redis', |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Available adapters. |
|
34
|
|
|
* |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
private $adapters = [ |
|
38
|
|
|
'buzz' => 'BuzzHttpAdapter', |
|
39
|
|
|
'curl' => 'CurlHttpAdapter', |
|
40
|
|
|
'guzzle' => 'GuzzleHttpAdapter', |
|
41
|
|
|
'socket' => 'SocketHttpAdapter', |
|
42
|
|
|
'zend' => 'ZendHttpAdapter', |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Available providers. |
|
47
|
|
|
* |
|
48
|
|
|
* @var array |
|
49
|
|
|
*/ |
|
50
|
|
|
private $providers = [ |
|
51
|
|
|
'free_geo_ip' => 'FreeGeoIp', |
|
52
|
|
|
'host_ip' => 'HostIp', |
|
53
|
|
|
'ip_info_db' => 'IpInfoDb', |
|
54
|
|
|
'google_maps' => 'GoogleMaps', |
|
55
|
|
|
'google_maps_business' => 'GoogleMapsBusiness', |
|
56
|
|
|
'bing_maps' => 'BingMaps', |
|
57
|
|
|
'openstreetmaps' => 'OpenStreetMap', |
|
58
|
|
|
'cloudmade' => 'CloudMade', |
|
59
|
|
|
'geoip' => 'Geoip', |
|
60
|
|
|
'map_quest' => 'MapQuest', |
|
61
|
|
|
'oio_rest' => 'OIORest', |
|
62
|
|
|
'geocoder_ca' => 'GeocoderCa', |
|
63
|
|
|
'geocoder_us' => 'GeocoderUs', |
|
64
|
|
|
'ign_openls' => 'IGNOpenLS', |
|
65
|
|
|
'data_science_toolkit' => 'DataScienceToolkit', |
|
66
|
|
|
'yandex' => 'Yandex', |
|
67
|
|
|
'geo_plugin' => 'GeoPlugin', |
|
68
|
|
|
'geo_ips' => 'GeoIPs', |
|
69
|
|
|
'maxmind' => 'MaxMind', |
|
70
|
|
|
'geonames' => 'Geonames', |
|
71
|
|
|
'ip_geo_base' => 'IpGeoBase', |
|
72
|
|
|
'baidu' => 'Baidu', |
|
73
|
|
|
'tomtom' => 'TomTom', |
|
74
|
|
|
'arcgis_online' => 'ArcGISOnline', |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Available dumpers. |
|
79
|
|
|
* |
|
80
|
|
|
* @var array |
|
81
|
|
|
*/ |
|
82
|
|
|
private $dumpers = [ |
|
83
|
|
|
'gpx' => 'Gpx', |
|
84
|
|
|
'geojson' => 'GeoJson', |
|
85
|
|
|
'kml' => 'Kml', |
|
86
|
|
|
'wkb' => 'Wkb', |
|
87
|
|
|
'wkt' => 'Wkt', |
|
88
|
|
|
]; |
|
89
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Returns the cache class name. |
|
93
|
|
|
* The default cache is Redis. |
|
94
|
|
|
* |
|
95
|
|
|
* @param string $cache The name of the cache to use. |
|
96
|
|
|
* |
|
97
|
|
|
* @return string The name of the cache to use. |
|
98
|
|
|
*/ |
|
99
|
|
|
protected function getCache($cache) |
|
100
|
|
|
{ |
|
101
|
|
|
$cache = $this->lowerize((trim($cache))); |
|
102
|
|
|
$cache = array_key_exists($cache, $this->caches) |
|
103
|
|
|
? $this->caches[$cache] |
|
104
|
|
|
: $this->caches['redis']; |
|
105
|
|
|
|
|
106
|
|
|
return '\\League\\Geotools\\Cache\\' . $cache; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Returns the list of available caches sorted by alphabetical order. |
|
111
|
|
|
* |
|
112
|
|
|
* @return string The list of available caches comma separated. |
|
113
|
|
|
*/ |
|
114
|
3 |
|
protected function getCaches() |
|
115
|
|
|
{ |
|
116
|
3 |
|
ksort($this->caches); |
|
117
|
|
|
|
|
118
|
3 |
|
return implode(', ', array_keys($this->caches)); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Returns the adapter class name. |
|
123
|
|
|
* The default adapter is cURL. |
|
124
|
|
|
* |
|
125
|
|
|
* @param string $adapter The name of the adapter to use. |
|
126
|
|
|
* |
|
127
|
|
|
* @return string The name of the adapter class to use. |
|
128
|
|
|
*/ |
|
129
|
|
|
protected function getAdapter($adapter) |
|
130
|
|
|
{ |
|
131
|
|
|
$adapter = $this->lowerize((trim($adapter))); |
|
132
|
|
|
$adapter = array_key_exists($adapter, $this->adapters) |
|
133
|
|
|
? $this->adapters[$adapter] |
|
134
|
|
|
: $this->adapters['curl']; |
|
135
|
|
|
|
|
136
|
|
|
return '\\Ivory\\HttpAdapter\\' . $adapter; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Returns the list of available adapters sorted by alphabetical order. |
|
141
|
|
|
* |
|
142
|
|
|
* @return string The list of available adapters comma separated. |
|
143
|
|
|
*/ |
|
144
|
3 |
|
protected function getAdapters() |
|
145
|
|
|
{ |
|
146
|
3 |
|
ksort($this->adapters); |
|
147
|
|
|
|
|
148
|
3 |
|
return implode(', ', array_keys($this->adapters)); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Returns the provider class name. |
|
153
|
|
|
* The default provider is Google Maps. |
|
154
|
|
|
* |
|
155
|
|
|
* @param string $provider The name of the provider to use. |
|
156
|
|
|
* |
|
157
|
|
|
* @return string The name of the provider class to use. |
|
158
|
|
|
*/ |
|
159
|
|
|
protected function getProvider($provider) |
|
160
|
|
|
{ |
|
161
|
|
|
$provider = $this->lowerize((trim($provider))); |
|
162
|
|
|
$provider = array_key_exists($provider, $this->providers) |
|
163
|
|
|
? $this->providers[$provider] |
|
164
|
|
|
: $this->providers['google_maps']; |
|
165
|
|
|
|
|
166
|
|
|
return '\\Geocoder\\Provider\\' . $provider; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Returns the list of available providers sorted by alphabetical order. |
|
171
|
|
|
* |
|
172
|
|
|
* @return string The list of available providers comma separated. |
|
173
|
|
|
*/ |
|
174
|
3 |
|
protected function getProviders() |
|
175
|
|
|
{ |
|
176
|
3 |
|
ksort($this->providers); |
|
177
|
|
|
|
|
178
|
3 |
|
return implode(', ', array_keys($this->providers)); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Returns the dumper class name. |
|
183
|
|
|
* The default dumper is WktDumper. |
|
184
|
|
|
* |
|
185
|
|
|
* @param string $dumper The name of the dumper to use. |
|
186
|
|
|
* |
|
187
|
|
|
* @return string The name of the dumper class to use. |
|
188
|
|
|
*/ |
|
189
|
|
|
protected function getDumper($dumper) |
|
190
|
|
|
{ |
|
191
|
|
|
$dumper = $this->lowerize((trim($dumper))); |
|
192
|
|
|
$dumper = array_key_exists($dumper, $this->dumpers) |
|
193
|
|
|
? $this->dumpers[$dumper] |
|
194
|
|
|
: $this->dumpers['wkt']; |
|
195
|
|
|
|
|
196
|
|
|
return '\\Geocoder\\Dumper\\' . $dumper; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Returns the list of available dumpers sorted by alphabetical order. |
|
201
|
|
|
* |
|
202
|
|
|
* @return string The list of available dumpers comma separated. |
|
203
|
|
|
*/ |
|
204
|
3 |
|
protected function getDumpers() |
|
205
|
|
|
{ |
|
206
|
3 |
|
ksort($this->dumpers); |
|
207
|
|
|
|
|
208
|
3 |
|
return implode(', ', array_keys($this->dumpers)); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Make a string lowercase. |
|
213
|
|
|
* |
|
214
|
|
|
* @param string $string A string to lowercase. |
|
215
|
|
|
* |
|
216
|
|
|
* @return string The lowercased string. |
|
217
|
|
|
*/ |
|
218
|
|
|
private function lowerize($string) |
|
219
|
|
|
{ |
|
220
|
|
|
return extension_loaded('mbstring') ? mb_strtolower($string, 'UTF-8') : strtolower($string); |
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
|