/** * Returns the location for given zip code * * @param string $zipCode * * @return Region * * @throws \EBT\GeoZipLocation\Exception\ResourceNotFoundException* */ public function getLocationForZip($zipCode) { $zipCode = $this->getSanitizeZipCode($zipCode); if (false === $zipCode) { throw new ResourceNotFoundException(sprintf('Unable to find a region for %s zipcode', $zipCode)); } /* Germany zip codes are tricky, we have to * 1) search one by one * 2) if step 1) fails, we have to look in the intervals :o */ foreach ($this->map as $mapZipCode => $zipCodeContent) { /* Is map zip code was 5 digits, then we shall compare with our zip code */ if (strlen($mapZipCode) == 5) { if ($zipCode == $mapZipCode) { $area = $this->repo_area->getById($zipCodeContent[self::DATA_INDEX_AREA]); $zone = $this->repo_zone->getById($zipCodeContent[self::DATA_INDEX_ZONE]); $region = $this->repo_region->getById($zipCodeContent[self::DATA_INDEX_REGION]); $zone->setSubLocation($area); $region->setSubLocation($zone); return $region; } /* otherwise, it was an interval and we have to check if our zip code is on the interval */ } else { $zipCodeInterval = explode('-', $mapZipCode); if ($zipCode > $zipCodeInterval[0] && $zipCode < $zipCodeInterval[1]) { $area = $this->repo_area->getById($zipCodeContent[self::DATA_INDEX_AREA]); $zone = $this->repo_zone->getById($zipCodeContent[self::DATA_INDEX_ZONE]); $region = $this->repo_region->getById($zipCodeContent[self::DATA_INDEX_REGION]); $zone->setSubLocation($area); $region->setSubLocation($zone); return $region; } } } throw new ResourceNotFoundException(sprintf('Unable to find a region for %s zipcode', $zipCode)); }
/** * testGetAll */ public function testGetAll() { $areaRepository = new AreaRepository(); $this->assertContainsOnlyInstancesOf('EBT\\GeoZipLocation\\Translator\\DE\\Location\\Area', $areaRepository->getAll()); }