Ejemplo n.º 1
0
 /**
  * @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;
 }