geoIPLookup = $geoIPLookup; $this->locationsList = $locationsList; } /** * @inheritDoc */ public function validate(array $regions, array $counties, array $usaStates = [], ?string $ip = null): bool { if (! $this->geoIPLookup->canUse()) { throw new LocalizedException( __('Plumrocket IP Geolocation Lookup is disabled or no one GeoIP databases is enabled') ); } if ((empty($regions) && empty($counties)) || in_array(LocationsListInterface::ALL, $regions, true) ) { return true; } if (in_array(LocationsListInterface::EU, $regions, true) && $this->geoIPLookup->isInEuropeanUnion()) { return true; } $countryCode = $this->geoIPLookup->getCountryCode(); if (null !== $countryCode) { if ($usaStates && LocationsListInterface::COUNTRY_CODE_USA === $countryCode) { return in_array($this->geoIPLookup->getCurrentCountryState(), $usaStates, true); } return in_array($countryCode, $counties, true); } if (in_array(LocationsListInterface::UNKNOWN, $regions, true)) { return true; } return false; } /** * @inheritDoc */ public function validateByMergedOptions(array $options, array $usaStates = [], ?string $ip = null): bool { $allRegionsKey = array_column($this->locationsList->getRegions(), 'value'); $regions = []; $counties = []; foreach ($options as $option) { if (in_array($option, $allRegionsKey, true)) { $regions[] = $option; } else { $counties[] = $option; } } return $this->validate($regions, $counties, $usaStates, $ip); } }