<?php
namespace League\Geotools\CLI\Command\Geocoder;
use Psr\Cache\CacheItemPoolInterface;
class Command extends \Symfony\Component\Console\Command\Command
{
private $providers = [
'free_geo_ip' => 'FreeGeoIp',
'host_ip' => 'HostIp',
'ip_info_db' => 'IpInfoDb',
'google_maps' => 'GoogleMaps',
'google_maps_business' => 'GoogleMapsBusiness',
'bing_maps' => 'BingMaps',
'openstreetmap' => 'OpenStreetMap',
'cloudmade' => 'CloudMade',
'geoip' => 'Geoip',
'map_quest' => 'MapQuest',
'oio_rest' => 'OIORest',
'geocoder_ca' => 'GeocoderCa',
'geocoder_us' => 'GeocoderUs',
'ign_openls' => 'IGNOpenLS',
'data_science_toolkit' => 'DataScienceToolkit',
'yandex' => 'Yandex',
'geo_plugin' => 'GeoPlugin',
'geo_ips' => 'GeoIPs',
'maxmind' => 'MaxMind',
'geonames' => 'Geonames',
'ip_geo_base' => 'IpGeoBase',
'baidu' => 'Baidu',
'tomtom' => 'TomTom',
'arcgis_online' => 'ArcGISOnline',
];
private $dumpers = [
'gpx' => 'Gpx',
'geojson' => 'GeoJson',
'kml' => 'Kml',
'wkb' => 'Wkb',
'wkt' => 'Wkt',
];
protected function getCache($factoryCallable)
{
$factoryCallable = $this->lowerize((trim($factoryCallable)));
if (!is_callable($factoryCallable)) {
throw new \LogicException(sprintf('Cache must be called with a valid callable on the format "Example\Acme::create". "%s" given.', $factoryCallable));
}
$psr6 = call_user_func($factoryCallable);
if (!$psr6 instanceof CacheItemPoolInterface) {
throw new \LogicException('Return value of factory callable must be a CacheItemPoolInterface');
}
return $psr6;
}
protected function getProvider($provider)
{
$provider = $this->lowerize((trim($provider)));
$provider = array_key_exists($provider, $this->providers)
? $this->providers[$provider]
: $this->providers['google_maps'];
return '\\Geocoder\\Provider\\' . $provider . '\\' . $provider;
}
protected function getProviders()
{
ksort($this->providers);
return implode(', ', array_keys($this->providers));
}
protected function getDumper($dumper)
{
$dumper = $this->lowerize((trim($dumper)));
$dumper = array_key_exists($dumper, $this->dumpers)
? $this->dumpers[$dumper]
: $this->dumpers['wkt'];
return '\\Geocoder\\Dumper\\' . $dumper;
}
protected function getDumpers()
{
ksort($this->dumpers);
return implode(', ', array_keys($this->dumpers));
}
private function lowerize($string)
{
return extension_loaded('mbstring') ? mb_strtolower($string, 'UTF-8') : strtolower($string);
}
}