getSupportedRegions() public method

Convenience method to get a list of what regions the library has metadata for.
public getSupportedRegions ( ) : array
return array
コード例 #1
0
 /**
  * @dataProvider localeList
  * @param string $regionCode
  * @param string $countryName
  */
 public function testLocales($regionCode, $countryName)
 {
     if (!in_array($regionCode, $this->phoneUtil->getSupportedRegions())) {
         $this->markTestSkipped("{$regionCode} is not supported");
     }
     $phoneNumber = $this->phoneUtil->getExampleNumberForType($regionCode, PhoneNumberType::FIXED_LINE_OR_MOBILE);
     $this->assertContains($regionCode, CountryCodeToRegionCodeMap::$countryCodeToRegionCodeMap[$phoneNumber->getCountryCode()]);
     $this->assertEquals($regionCode, $this->phoneUtil->getRegionCodeForNumber($phoneNumber));
     $this->assertEquals($countryName, $this->geocoder->getDescriptionForValidNumber($phoneNumber, 'en', 'ZZ'), "Checking {$phoneNumber} is part of {$countryName}");
 }
コード例 #2
0
 /**
  * @param string $regionCode
  * @return $this
  */
 public function setRegionCode($regionCode)
 {
     $regionCode = (string) $regionCode;
     if (!in_array($regionCode, $this->libPhoneNumber->getSupportedRegions())) {
         throw new InvalidArgumentException('Region code "' . $regionCode . '" is not currently supported by libPhoneNumber.');
     }
     $this->regionCode = $regionCode;
     return $this;
 }
コード例 #3
0
ファイル: Phone.php プロジェクト: iPublikuj/phone
 /**
  * @param string $country
  *
  * @return string
  *
  * @throws Exceptions\NoValidCountryException
  */
 protected function validateCountry($country)
 {
     // Country code have to be upper-cased
     $country = strtoupper($country);
     // Correct auto or null value
     if ($country === 'AUTO' || $country === NULL) {
         return 'AUTO';
     } else {
         if (strlen($country) === 2 && ctype_alpha($country) && in_array($country, $this->phoneNumberUtil->getSupportedRegions())) {
             return $country;
         } else {
             throw new Exceptions\NoValidCountryException('Provided country code "' . $country . '" is not valid. Provide valid country code or AUTO for automatic detection.');
         }
     }
 }
コード例 #4
0
 public function testGetSupportedRegions()
 {
     $this->assertGreaterThan(0, count($this->phoneUtil->getSupportedRegions()));
 }
コード例 #5
-1
 public function isValid($value)
 {
     if (!is_scalar($value)) {
         $this->error(self::INVALID);
         return false;
     }
     $country = $this->getCountry();
     $supportedCountries = $this->libPhoneNumber->getSupportedRegions();
     if (!in_array($country, $supportedCountries)) {
         $this->error(self::UNSUPPORTED);
         return false;
     }
     try {
         $numberProto = $this->libPhoneNumber->parse($value, $country);
     } catch (NumberParseException $e) {
         $this->error(self::INVALID_NUMBER);
         return false;
     }
     if (!$this->libPhoneNumber->isValidNumber($numberProto)) {
         $this->error(self::INVALID_NUMBER);
         return false;
     }
     $region = $this->libPhoneNumber->getRegionCodeForNumber($numberProto);
     if ($this->libPhoneNumber->isValidNumberForRegion($numberProto, $region)) {
         return true;
     }
     $this->error(self::NO_MATCH);
     return false;
 }