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); }
/** * @return \Geocoder\ProviderAggregator * @throws RuntimeException */ public static function getGeocoder() { if (!self::$addressGeocoder) { $adapter = self::config()->adapter; if (!class_exists($adapter)) { throw new RuntimeException("Adapter class {$adapter} is not defined"); } $adaperOptions = self::config()->adapter_options; $configuration = new \Ivory\HttpAdapter\Configuration(); foreach ($adaperOptions as $adapterParam => $adapterValue) { $method = 'set' . ucfirst($adapterParam); $configuration->{$method}($adapterValue); } $geocoder = new \Geocoder\ProviderAggregator(); $adapterInstance = new $adapter($configuration); $providers = self::config()->providers; foreach ($providers as $provider => $params) { if (isset($params['locale'])) { $params['locale'] = i18n::get_locale(); } array_unshift($params, $adapterInstance); //put the adapter as the first param $class = '\\Geocoder\\Provider\\' . $provider; if (!class_exists($class)) { throw new RuntimeException("Provider class {$class} is not defined"); } $reflectionClass = new ReflectionClass($class); $providerInstance = $reflectionClass->newInstanceArgs($params); $geocoder->registerProvider($providerInstance); } self::$addressGeocoder = $geocoder; } return self::$addressGeocoder; }
| Register Container Bindings |-------------------------------------------------------------------------- | | Now we will register a few bindings in the service container. We will | register the exception handler and the console kernel. You may add | your own bindings here if you like or you can make another file. | */ $app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class); $app->singleton(Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class); $app->bind('Topor\\Topor', function ($app) { return new \Topor\Topor(['logs_dir' => storage_path('/logs'), 'best' => ['env' => \Topor\Best::ENV_PROD, 'partner_id' => 7777773, 'credentials' => [__DIR__ . '/best.key', __DIR__ . '/best.crt']]]); }); $app->bind('Geocoder\\Geocoder', function ($app) { $adapter = new \Ivory\HttpAdapter\Guzzle6HttpAdapter(); $geocoder = new \Geocoder\ProviderAggregator(3); $geocoder->registerProviders([new \Geocoder\Provider\Yandex($adapter, 'ru_RU'), new \Geocoder\Provider\GoogleMaps($adapter, 'ru_RU')]); return $geocoder; }); /* |-------------------------------------------------------------------------- | Register Middleware |-------------------------------------------------------------------------- | | Next, we will register the middleware with the application. These can | be global middleware that run before and after each request into a | route or middleware that'll be assigned to some specific routes. | */ // $app->middleware([ // // Illuminate\Cookie\Middleware\EncryptCookies::class,