From a41851b9b86b90191f97ad6ebb0304a25b4096b2 Mon Sep 17 00:00:00 2001 From: Soban Mahmod Date: Thu, 7 Jul 2022 14:45:41 +0500 Subject: [PATCH] receive ip handler implementation and use it for ip selection --- src/ipinfolaravel.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ipinfolaravel.php b/src/ipinfolaravel.php index a06b523..fdf3a6b 100644 --- a/src/ipinfolaravel.php +++ b/src/ipinfolaravel.php @@ -5,6 +5,7 @@ use Closure; use ipinfo\ipinfo\IPinfo as IPinfoClient; use ipinfo\ipinfolaravel\DefaultCache; +use ipinfo\ipinfolaravel\iphandler\DefaultIPHandler; class ipinfolaravel { @@ -26,6 +27,12 @@ class ipinfolaravel */ public $filter = null; + /** + * Provides ip. + * @var ipinfo\ipinfolaravel\iphandler\IPHandlerInterface + */ + public $ip_selector = null; + const CACHE_MAXSIZE = 4096; const CACHE_TTL = 60 * 24; @@ -43,7 +50,7 @@ public function handle($request, Closure $next) $details = null; } else { try { - $details = $this->ipinfo->getDetails($request->ip()); + $details = $this->ipinfo->getDetails($this->ip_selector->getIP($request)); } catch (\Exception $e) { $details = null; @@ -70,6 +77,7 @@ public function configure() $this->access_token = config('services.ipinfo.access_token', null); $this->filter = config('services.ipinfo.filter', [$this, 'defaultFilter']); $this->no_except = config('services.ipinfo.no_except', false); + $this->ip_selector = config('services.ipinfo.ip_selector', new DefaultIPHandler()); if ($custom_countries = config('services.ipinfo.countries_file', null)) { $this->settings['countries_file'] = $custom_countries; @@ -83,12 +91,6 @@ public function configure() $this->settings['cache'] = new DefaultCache($maxsize, $ttl); } - if ($custom_iphandler = config('services.ipinfo.iphandler', null)) { - $this->settings['iphandler'] = $custom_iphandler; - } else { - // TODO: Handle this case, with default options - } - $this->ipinfo = new IPinfoClient($this->access_token, $this->settings); }