Ejemplo n.º 1
0
 protected function initSypex()
 {
     $geo = $this->config->get('sypexgeo.use_db') ? new SxGeo($this->config->get('sypexgeo.db_path')) : new SxGeoHttp($this->config->get('sypexgeo.licence_key'));
     if ($geo instanceof ConfigAwareInterface) {
         $geo->setConfig($this->config);
     }
     $sypex = new SypexGeo($geo, $this->config);
     return $sypex;
 }
Ejemplo n.º 2
0
 /**
  * Метод возваращает данные полученные от api.sypexgeo.net
  * @param $ip
  * @return mixed
  */
 public function getCityFull($ip)
 {
     $view = $this->config->get('sypexgeo.sypexgeo.view', array());
     $url = $this->get_path($view, $ip);
     $get_array = 'get_array_' . $view;
     $apiSypexGeo = $this->file_get_contents_url($url);
     $arrSypexGeo = $this->{$get_array}($apiSypexGeo);
     return $arrSypexGeo;
 }
Ejemplo n.º 3
0
 /**
  * @param string $ip
  * @return bool
  */
 public function get($ip = '')
 {
     if (empty($ip)) {
         $this->getIP();
     } else {
         if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
             return false;
         } else {
             $this->ip = $ip;
             $this->ipAsLong = sprintf('%u', ip2long($ip));
         }
     }
     $data = $this->_sypex->getCityFull($this->ip, $this->config);
     if (isset($data['city'])) {
         $this->city = $data['city'];
     }
     if (isset($data['region'])) {
         $this->region = $data['region'];
     }
     if (isset($data['country'])) {
         $this->country = $data['country'];
     }
     return empty($data) ? $this->config->get('sypexgeo.default_location', array()) : $data;
 }