Ejemplo n.º 1
0
 /**
  * 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 (!$zipCode) {
         throw new TranslatorNotFoundException(sprintf('Zip code \'%s\' is not valid!', $zipCode));
     }
     /*
      * Italian has a mapping one to one (zipcodee => geolocation), so, we just need to verify if
      * the zipcode exists on the mapping. Otherwise we throw an excption
      */
     if (isset($this->map[$zipCode])) {
         $area = $this->repo_area->getById($this->map[$zipCode][self::DATA_INDEX_AREA]);
         $zone = $this->repo_zone->getById($this->map[$zipCode][self::DATA_INDEX_ZONE]);
         $region = $this->repo_region->getById($this->map[$zipCode][self::DATA_INDEX_REGION]);
         $zone->setSubLocation($area);
         $region->setSubLocation($zone);
         return $region;
     }
     /* If we reach this point then no region was found. throwing an error */
     throw new ResourceNotFoundException(sprintf('Unable to find a region for \'%s\' zipcode', $zipCode));
 }
Ejemplo n.º 2
0
 /**
  * testGetAll
  */
 public function testGetAll()
 {
     $r = new AreaRepository();
     $this->assertContainsOnlyInstancesOf('EBT\\GeoZipLocation\\Translator\\IT\\Location\\Area', $r->getAll());
 }