Exemplo n.º 1
0
 /**
  * Returns the location for given zip code
  *
  * @param string $wantedZipCode
  *
  * @return Region
  *
  * @throws \EBT\GeoZipLocation\Exception\ResourceNotFoundException
  */
 public function getLocationForZip($wantedZipCode)
 {
     $wantedZipCode = $this->getSanitizeZipCode($wantedZipCode);
     if (false !== $wantedZipCode) {
         $intWantedZipCode = (int) $wantedZipCode;
         foreach ($this->map as $postalCodeStart => $mapping) {
             if ($intWantedZipCode >= $postalCodeStart) {
                 $area = $this->repo_area->getById($mapping[self::DATA_INDEX_AREA]);
                 $zone = $this->repo_zone->getById($mapping[self::DATA_INDEX_ZONE]);
                 $region = $this->repo_region->getById($mapping[self::DATA_INDEX_REGION]);
             } else {
                 /* Already found in last cycle so end the search */
                 break;
             }
         }
         if (!isset($area)) {
             /* this will happen when $intWantedZipCode is lower than the first valid zipcode */
             throw new ResourceNotFoundException(sprintf('Unable to find a region for %s zipcode', $wantedZipCode));
         }
         $zone->setSubLocation($area);
         $region->setSubLocation($zone);
         return $region;
     }
     throw new ResourceNotFoundException(sprintf('Unable to find a region for %s zipcode', $wantedZipCode));
 }
 /**
  * testGetAll
  */
 public function testGetAll()
 {
     $r = new ZoneRepository();
     $this->assertContainsOnlyInstancesOf('EBT\\GeoZipLocation\\Translator\\BR\\Location\\Zone', $r->getAll());
 }