本文整理匯總了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}");
}
示例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;
}
示例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.');
}
}
}
示例4: testGetSupportedRegions
public function testGetSupportedRegions()
{
$this->assertGreaterThan(0, count($this->phoneUtil->getSupportedRegions()));
}
示例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;
}