-
Notifications
You must be signed in to change notification settings - Fork 9
/
SypexGeo.php
78 lines (69 loc) · 1.49 KB
/
SypexGeo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace omnilight\sypexgeo;
use omnilight\sypexgeo\vendor\SxGeo;
use yii\base\Component;
/**
* Class SypexGeo is the wrapper for the SxGeo class that provides ability to use it as
* application component
*
* @property SxGeo $sxGeo Direct access to the SxGeo class
*/
class SypexGeo extends Component
{
/**
* @var SxGeo
*/
protected $_sxGeo;
/**
* Path to to the database file for Sypex Geo
* @var string
*/
public $database;
/**
* Access mode to the Sypex database
* @var int
*/
public $accessMode = SxGeo::SXGEO_FILE;
/**
* @param string $ip
* @return array|bool false if city is not detected
*/
public function getCity($ip)
{
return $this->getSxGeo()->getCity($ip);
}
/**
* @param $ip
* @return array
*/
public function getCountry($ip)
{
return $this->getSxGeo()->getCountry($ip);
}
/**
* @param string $ip
* @return integer
*/
public function getCountryId($ip)
{
return $this->getSxGeo()->getCountryId($ip);
}
/**
* @param string $ip
* @return array
*/
public function getCityFull($ip)
{
return $this->getSxGeo()->getCityFull($ip);
}
/**
* @return SxGeo
*/
public function getSxGeo()
{
if ($this->_sxGeo === null) {
$this->_sxGeo = new SxGeo(\Yii::getAlias($this->database), $this->accessMode);
}
return $this->_sxGeo;
}
}