本文整理匯總了PHP中libphonenumber\PhoneNumberUtil::getExampleNumberForType方法的典型用法代碼示例。如果您正苦於以下問題:PHP PhoneNumberUtil::getExampleNumberForType方法的具體用法?PHP PhoneNumberUtil::getExampleNumberForType怎麽用?PHP PhoneNumberUtil::getExampleNumberForType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類libphonenumber\PhoneNumberUtil
的用法示例。
在下文中一共展示了PhoneNumberUtil::getExampleNumberForType方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: checkNumbersValidAndCorrectType
private function checkNumbersValidAndCorrectType($exampleNumberRequestedType, $possibleExpectedTypes, $regionCode)
{
$exampleNumber = $this->phoneNumberUtil->getExampleNumberForType($regionCode, $exampleNumberRequestedType);
if ($exampleNumber !== null) {
$this->assertTrue($this->phoneNumberUtil->isValidNumber($exampleNumber), "Failed validation for {$exampleNumber}");
// We know the number is valid, now we check the type.
$exampleNumberType = $this->phoneNumberUtil->getNumberType($exampleNumber);
$this->assertContains($exampleNumberType, $possibleExpectedTypes, "Wrong type for {$exampleNumber}");
}
}
示例2: 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}");
}
示例3: testGetExampleNumber
public function testGetExampleNumber()
{
$this->assertEquals(self::$deNumber, $this->phoneUtil->getExampleNumber(RegionCode::DE));
$this->assertEquals(self::$deNumber, $this->phoneUtil->getExampleNumberForType(RegionCode::DE, PhoneNumberType::FIXED_LINE));
$this->assertEquals(null, $this->phoneUtil->getExampleNumberForType(RegionCode::DE, PhoneNumberType::MOBILE));
// For the US, the example number is placed under general description, and hence should be used
// for both fixed line and mobile, so neither of these should return null.
$this->assertNotNull($this->phoneUtil->getExampleNumberForType(RegionCode::US, PhoneNumberType::FIXED_LINE));
$this->assertNotNull($this->phoneUtil->getExampleNumberForType(RegionCode::US, PhoneNumberType::MOBILE));
// CS is an invalid region, so we have no data for it.
$this->assertNull($this->phoneUtil->getExampleNumberForType(RegionCode::CS, PhoneNumberType::MOBILE));
// RegionCode 001 is reserved for supporting non-geographical country calling code. We don't
// support getting an example number for it with this method.
$this->assertEquals(null, $this->phoneUtil->getExampleNumber(RegionCode::UN001));
}