public function get()
 {
     $context = Context::factory();
     // get default parameters from config
     $config = $context->ns('geocodit');
     $defaultProfile = $config->getValue('trust', 'geocodit', $this->VALID_PROFILE());
     $defaultAddress = $config->getValue('defaultAddress', 'Via Montefiori 13, Esino Lario', FILTER_SANITIZE_STRING);
     $penality = $config->getValue('penality', 2, $this->VALID_PENALITY());
     // get input patrameters from URL quesry string
     $input = $context->ns(INPUT_GET);
     $query = $input->getValue('q', $defaultAddress, FILTER_SANITIZE_STRING);
     $profile = $input->getValue('trust', $defaultProfile, self::VALID_PROFILE());
     $geocoder = new \Geocoder\ProviderAggregator();
     $adapter = new \Ivory\HttpAdapter\CurlHttpAdapter();
     // chain all supported providers
     $chain = new \Geocoder\Provider\Chain(array());
     foreach ($this->PROFILES[$profile] as $providerName) {
         $provider = $this->geocoderFactory($adapter, trim($providerName));
         $chain->add($provider);
     }
     $geocoder->registerProvider($chain);
     // Call toponym resolution providers
     $address = $geocoder->limit(1)->geocode($query)->first();
     // apply penality (just to avoid abuse, set to 0 in config file to disable)
     if ($penality > 0) {
         usleep($penality * 1000000);
     }
     return $this->stateTransfer($address);
 }
 public function testLocalVar()
 {
     $myvar = 'ok';
     // define a variable in local scope
     $v = CX::factory(get_defined_vars())->ns(CX::LOCAL)->getValue('myvar');
     $this->assertEquals($v, 'ok');
 }
 public function get()
 {
     $context = Context::factory();
     // get default parameters from config
     $config = $context->ns('geocodit');
     $defaultAddress = $config->getValue('defaultAddress', 'Via Montefiori 13, Esino Lario');
     $penality = $config->getValue('penality', 2);
     // get input patrameters from URL quesry string
     $input = $context->ns(INPUT_GET);
     $query = $input->getValue('q', $defaultAddress);
     $adapter = new \Ivory\HttpAdapter\CurlHttpAdapter();
     $benchmark = new Benchmark($query);
     foreach (explode('|', self::SUPPORTED_PROVIDERS) as $providerName) {
         $provider = $this->geocoderFactory($adapter, trim($providerName));
         $benchmark->compare($provider);
     }
     usleep($penality * 1000000);
     return $this->stateTransfer($benchmark);
 }
 public function geocoderFactory($adapter, $providerName)
 {
     $context = Context::factory();
     $input = $context->ns(INPUT_GET);
     $config = $context->ns('geocodit');
     $locale = 'it_IT';
     switch ($providerName) {
         case 'geocoditOSM':
             $endpoint = $config->getValue('endpoint', 'https://hub1.linkeddata.center/demo');
             $kbid = $config->getValue('kbid', 'demo');
             $secretKey = $config->getValue('secretKey', 'demo');
             $geocoder = new \Geocodit\Provider\GeocoditOSM($adapter, $kbid, $secretKey, $endpoint);
             break;
         case 'geocodit':
             $endpoint = $config->getValue('endpoint', 'https://hub1.linkeddata.center/demo');
             $kbid = $config->getValue('kbid', 'demo');
             $secretKey = $config->getValue('secretKey', 'demo');
             $geocoder = new \Geocodit\Provider\Geocodit($adapter, $kbid, $secretKey, $endpoint);
             break;
         case 'google_maps':
             $googleApiKey = $config->getValue('googleApiKey', V::NULL_AS_DEFAULT);
             $geocoder = new \Geocoder\Provider\GoogleMaps($adapter, $locale, 'Italy', true, $googleApiKey);
             break;
         case 'openstreetmap':
             $geocoder = new \Geocoder\Provider\OpenStreetMap($adapter, $locale);
             break;
         case 'bing_maps':
             $bingApiKey = $config->getValue('bingApiKey', 'here_your_bing_api_key');
             $geocoder = new \Geocoder\Provider\BingMaps($adapter, $bingApiKey, $locale);
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Unknown geocoder provider name "%s".', $providerName));
             break;
     }
     return $geocoder;
 }
Example #5
0
 * limitations under the License.
 * 
 */
require '../../vendor/autoload.php';
use BOTK\Core\EndPointFactory, BOTK\Core\ErrorManager;
// Control errors
use Geocodit\View\GoogleAnalyticsEnabledRenderer;
// for CSS
use BOTK\Context\Context;
// get config vars and other inputs
use BOTK\Context\ContextNameSpace as CX;
// search configs files in  in config and /etc/geocodit directories
if (!isset($_ENV['BOTK_CONFIGDIR'])) {
    if (file_exists(__DIR__ . '/../../config/geocodit.ini')) {
        $_ENV['BOTK_CONFIGDIR'] = realpath(__DIR__ . '/../../config');
    } elseif (is_dir('/etc/geocodit')) {
        $_ENV['BOTK_CONFIGDIR'] = '/etc/geocodit';
    }
}
// Enable Universal Analytics code
$UA = Context::factory()->ns('geocodit')->getValue('UA', CX::NULL_AS_DEFAULT);
GoogleAnalyticsEnabledRenderer::$UniversalAnalyticsId = $UA;
// Enable the catching of PHP errors
$errorManager = ErrorManager::getInstance()->registerErrorHandler();
try {
    $endpoint = EndPointFactory::make('Geocodit\\ApiEndpoint');
    $result = $endpoint->run();
} catch (Exception $e) {
    $result = ErrorManager::getInstance()->render($e);
}
echo $result;
Example #6
0
<?php

require '../vendor/autoload.php';
DEFINE('DEMO_ENDPOINT', 'https://hub1.linkeddata.center/demo');
// search configs files in  in config and /etc/geocodit directories
if (!isset($_ENV['BOTK_CONFIGDIR'])) {
    if (file_exists(__DIR__ . '/../config/geocodit.ini')) {
        $_ENV['BOTK_CONFIGDIR'] = realpath(__DIR__ . '/../config');
    } elseif (is_dir('/etc/geocodit')) {
        $_ENV['BOTK_CONFIGDIR'] = '/etc/geocodit';
    }
}
$config = \BOTK\Context\Context::factory()->ns('geocodit');
$penality = $config->getValue('penality', 2);
$endpoint = $config->getValue('endpoint', DEMO_ENDPOINT);
$defaultAddress = $config->getValue('defaultAddress', 'Via Montefiori 13, Esino Lario');
// test google maps and bing maps credentials
$googleApiKeyNotSetWarning = $config->getValue('googleApiKey', '') ? '' : "<li style='color: red'>WARNING: google maps api key not available (continue at your risk)</li>";
$bingApiKeyNotSetWarning = $config->getValue('bingApiKey', '') ? '' : "<li style='color: red' >WARNING: bing maps api key not available, bing maps will return errors</li>";
// Enable Universal Analytics code
$UASnippet = \Geocodit\View\GoogleAnalyticsEnabledRenderer::GoogleAnalyticsSnippet($config->getValue('UA', ''));
$passwordHint = $endpoint == DEMO_ENDPOINT ? ' (demo/demo)' : '';
?>
<!DOCTYPE html>
<html>
    <head>
		<meta charset='utf-8'>
		<link rel='stylesheet' type='text/css' href='http://linkeddata.center/resources/v4/css/doc.css'/>
		<style type='text/css'>
		    main {
		        font-family: monospace;
 public function testNoNamespace()
 {
     $v = CX::factory()->ns('nosample')->getValue('novar', 1);
     $this->assertEquals($v, 1);
 }