configUtils = $configUtils; } /** * @param $path * @param null $store * @param null $scope * @return mixed */ private function getConfigForCurrentSection($path, $store = null, $scope = null) { return $this->configUtils->getConfig( 'prgeoiplookup/'. $path, $store, $scope ); } /** * @inheritDoc */ public function isModuleEnabled($store = null, $scope = null): bool { return $this->configUtils->isSetFlag('prgeoiplookup/general/enabled', $store, $scope); } /** * @return bool */ public function isConfiguredForUse(): bool { return $this->isModuleEnabled() && $this->getEnableMethodsNumber(); } /** * @param int|string $store * @return bool */ public function enabledMaxmindGeoIp($store = null) { return (bool)$this->getConfigForCurrentSection( 'methods/' . self::MAXMIND_GROUP . '/enabled', $store ); } /** * @param int|string $store * @return string */ public function getMaxmindInstallMethod($store = null) { return $this->getConfigForCurrentSection( 'methods/' . self::MAXMIND_GROUP . '/install_method', $store ); } /** * @param int|string $store * @return bool */ public function enabledIpToCountryGeoIp($store = null) { return (bool)$this->getConfigForCurrentSection( 'methods/' . self::IPTOCOUNTRY_GROUP . '/enabled', $store ); } /** * @param int|string $store * @return string */ public function getIpToCountryInstallMethod($store = null) { return $this->getConfigForCurrentSection( 'methods/' . self::IPTOCOUNTRY_GROUP . '/install_method', $store ); } /** * @param int|string $store * @return bool */ public function enabledIpApiGeoIp($store = null) { return (bool)$this->getConfigForCurrentSection( 'methods/' . self::IPAPI_GROUP . '/enabled', $store ); } /** * @param null $store * @return bool */ public function useIpApiHttps($store = null) { return (bool) $this->getConfigForCurrentSection( 'methods/' . self::IPAPI_GROUP . '/use_https', $store ); } /** * @param null $store * @return bool */ private function getIpApiAccessKey($store = null) { return (string)$this->getConfigForCurrentSection( 'methods/' . self::IPAPI_GROUP . '/access_key', $store ); } /** * @param $ip * @return string */ public function getIpApiUrl($ip = self::DEFAULT_IP, $withAccessKey = true) { $apiUrl = self::IPAPI_CONNECTION_URL . '/' . $ip; if ($withAccessKey) { $apiUrl .= '?access_key=' . $this->getIpApiAccessKey(); } return $apiUrl; } /** * @param null $store * @return int */ public function getEnableMethodsNumber($store = null) { $methodsArray = [self::MAXMIND_GROUP, self::IPTOCOUNTRY_GROUP, self::IPAPI_GROUP]; $count = 0; foreach ($methodsArray as $method) { if ($this->getConfigForCurrentSection( 'methods/' . $method . '/enabled', $store )) { $count++; } } return $count; } }