Skip to content

Commit 18f27d2

Browse files
committed
seperate get and get data
1 parent c5bd5cc commit 18f27d2

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/GeoIP.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,27 @@ public function getIP()
8282
* @return array|string
8383
*/
8484
public function get($property = '')
85+
{
86+
$data = $this->getData();
87+
88+
if (!$property) {
89+
return $data;
90+
}
91+
92+
return array_get($data, $property, '');
93+
}
94+
95+
/**
96+
* Get an array or single item of geoip data
97+
*
98+
* @return array
99+
* @throws \PulkitJalan\GeoIP\Exceptions\GeoIPException
100+
*/
101+
protected function getData()
85102
{
86103
$ip = $this->getIP();
87104

105+
// check ip in memory
88106
$data = array_get($this->store, $ip);
89107

90108
if (!$data) {
@@ -94,14 +112,11 @@ public function get($property = '')
94112
throw new GeoIPException('Failed to get geoip data', 0, $e);
95113
}
96114

115+
// cache ip data in memory
97116
$this->store[$ip] = $data;
98117
}
99118

100-
if (!$property) {
101-
return $data;
102-
}
103-
104-
return array_get($data, $property, '');
119+
return $data;
105120
}
106121

107122
/**

0 commit comments

Comments
 (0)