コード例 #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);
     /*
      * In france the Zone Zip-code can be two or three digits if not found with two try with three
      * Example: Corse du sud (2A) == 200 && 201
      *          Guyane == 973
      */
     $partialZipCode = substr($zipCode, 0, 2);
     if (!isset($this->map[$partialZipCode])) {
         $partialZipCode = substr($zipCode, 0, 3);
     }
     if (false !== $zipCode && isset($this->map[$partialZipCode])) {
         $area = $this->repo_area->getById($this->map[$partialZipCode][self::DATA_INDEX_AREA]);
         $zone = $this->repo_zone->getById($this->map[$partialZipCode][self::DATA_INDEX_ZONE]);
         $region = $this->repo_region->getById($this->map[$partialZipCode][self::DATA_INDEX_REGION]);
         $zone->setSubLocation($area);
         $region->setSubLocation($zone);
         return $region;
     } else {
         throw new ResourceNotFoundException(sprintf('Unable to find a region for \'%s\' zipcode', $zipCode));
     }
 }
コード例 #2
0
 /**
  * testGetAll
  */
 public function testGetAll()
 {
     $r = new ZoneRepository();
     $this->assertContainsOnlyInstancesOf('EBT\\GeoZipLocation\\Translator\\FR\\Location\\Zone', $r->getAll());
 }