Ejemplo n.º 1
0
 public function testSetGetSubdivision2()
 {
     $location = new Location();
     $location->setSubdivision2('foo', 'bar');
     $this->assertSame('foo', $location->getSubdivision2Code());
     $this->assertSame('bar', $location->getSubdivision2Name());
 }
Ejemplo n.º 2
0
 /**
  * Returns the Location for the provided IPv6 address.
  *
  * @param string $ip6 IPv6 address.
  *
  * @throws ProviderGeoIpNotFound
  * @return Location
  */
 public function getLocationFromIPv6($ip6)
 {
     // create a cidr block
     $ip = $this->str($ip6)->explode(':');
     do {
         $ip->removeLast();
     } while ($ip->count() > 3);
     $subNet = $ip->implode(':')->val();
     $ipStart = floatval(Ipv6Helper::ip2LongV6($subNet . ':8000:0:0:0:0'));
     $cityBlock = CityBlockIp6Entity::findOne(['rangeStart' => $ipStart]);
     if (!$cityBlock) {
         $ipStart = floatval(Ipv6Helper::ip2LongV6($subNet . ':0:0:0:0:0'));
         $cityBlock = CityBlockIp6Entity::findOne(['rangeStart' => $ipStart]);
     }
     // verify that end ip is within range
     if (!$cityBlock || !(Ipv6Helper::ip2LongV6($ip6) <= $cityBlock->rangeEnd)) {
         throw new ProviderGeoIpNotFound('GeoIp entry not found');
     }
     // get location info
     $locationInfo = LocationEntity::findOne(['geoId' => $cityBlock->geoId]);
     // populate location variable
     $location = new Location();
     $location->setContinent($locationInfo->continentCode, $locationInfo->continentName);
     $location->setCountry($locationInfo->countryCode, $locationInfo->countryName);
     $location->setCityName($locationInfo->cityName);
     $location->setSubdivision1($locationInfo->subdivision1Code, $locationInfo->subdivision1Name);
     $location->setSubdivision2($locationInfo->subdivision2Code, $locationInfo->subdivision2Name);
     $location->setTimeZone($locationInfo->timeZone);
     return $location;
 }