當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PhoneNumberUtil::getSupportedRegions方法代碼示例

本文整理匯總了PHP中libphonenumber\PhoneNumberUtil::getSupportedRegions方法的典型用法代碼示例。如果您正苦於以下問題:PHP PhoneNumberUtil::getSupportedRegions方法的具體用法?PHP PhoneNumberUtil::getSupportedRegions怎麽用?PHP PhoneNumberUtil::getSupportedRegions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在libphonenumber\PhoneNumberUtil的用法示例。


在下文中一共展示了PhoneNumberUtil::getSupportedRegions方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testLocales

 /**
  * @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}");
 }
開發者ID:wakeless,項目名稱:libphonenumber-for-php,代碼行數:15,代碼來源:LocaleTest.php

示例2: setRegionCode

 /**
  * @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;
 }
開發者ID:uthando-cms,項目名稱:uthando-common,代碼行數:13,代碼來源:LibPhoneNumber.php

示例3: validateCountry

 /**
  * @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.');
         }
     }
 }
開發者ID:iPublikuj,項目名稱:phone,代碼行數:22,代碼來源:Phone.php

示例4: testGetSupportedRegions

 public function testGetSupportedRegions()
 {
     $this->assertGreaterThan(0, count($this->phoneUtil->getSupportedRegions()));
 }
開發者ID:wasabiNorman,項目名稱:libphonenumber-for-php,代碼行數:4,代碼來源:PhoneNumberUtilTest.php

示例5: isValid

 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;
 }
開發者ID:uthando-cms,項目名稱:uthando-common,代碼行數:29,代碼來源:PhoneNumber.php


注:本文中的libphonenumber\PhoneNumberUtil::getSupportedRegions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。