本文整理匯總了PHP中libphonenumber\PhoneNumberUtil::getMetadataForRegion方法的典型用法代碼示例。如果您正苦於以下問題:PHP PhoneNumberUtil::getMetadataForRegion方法的具體用法?PHP PhoneNumberUtil::getMetadataForRegion怎麽用?PHP PhoneNumberUtil::getMetadataForRegion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類libphonenumber\PhoneNumberUtil
的用法示例。
在下文中一共展示了PhoneNumberUtil::getMetadataForRegion方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGetInstanceLoadARMetadata
public function testGetInstanceLoadARMetadata()
{
$metadata = $this->phoneUtil->getMetadataForRegion(RegionCode::AR);
$this->assertEquals("AR", $metadata->getId());
$this->assertEquals(54, $metadata->getCountryCode());
$this->assertEquals("00", $metadata->getInternationalPrefix());
$this->assertEquals("0", $metadata->getNationalPrefix());
$this->assertEquals("0(?:(11|343|3715)15)?", $metadata->getNationalPrefixForParsing());
$this->assertEquals("9\$1", $metadata->getNationalPrefixTransformRule());
$this->assertEquals("\$2 15 \$3-\$4", $metadata->getNumberFormat(2)->getFormat());
$this->assertEquals("(9)(\\d{4})(\\d{2})(\\d{4})", $metadata->getNumberFormat(3)->getPattern());
$this->assertEquals("(9)(\\d{4})(\\d{2})(\\d{4})", $metadata->getIntlNumberFormat(3)->getPattern());
$this->assertEquals("\$1 \$2 \$3 \$4", $metadata->getIntlNumberFormat(3)->getFormat());
}
示例2: testCanBeInternationallyDialled
/**
* @dataProvider regionList
*/
public function testCanBeInternationallyDialled($regionCode)
{
$exampleNumber = null;
/** @var \libphonenumber\PhoneNumberDesc $desc */
$desc = $this->phoneNumberUtil->getMetadataForRegion($regionCode)->getNoInternationalDialling();
try {
if ($desc->hasExampleNumber()) {
$exampleNumber = $this->phoneNumberUtil->parse($desc->getExampleNumber(), $regionCode);
}
} catch (NumberParseException $e) {
}
if ($exampleNumber !== null && $this->phoneNumberUtil->canBeInternationallyDialled($exampleNumber)) {
$this->fail("Number {$exampleNumber} should not be internationally diallable");
}
}
示例3: testMaybeExtractCountryCode
public function testMaybeExtractCountryCode()
{
$number = new PhoneNumber();
$metadata = $this->phoneUtil->getMetadataForRegion(RegionCode::US);
// Note that for the US, the IDD is 011.
try {
$phoneNumber = "011112-3456789";
$strippedNumber = "123456789";
$countryCallingCode = 1;
$numberToFill = "";
$this->assertEquals($countryCallingCode, $this->phoneUtil->maybeExtractCountryCode($phoneNumber, $metadata, $numberToFill, true, $number), "Did not extract country calling code " . $countryCallingCode . " correctly.");
$this->assertEquals(CountryCodeSource::FROM_NUMBER_WITH_IDD, $number->getCountryCodeSource(), "Did not figure out CountryCodeSource correctly");
// Should strip and normalize national significant number.
$this->assertEquals($strippedNumber, $numberToFill, "Did not strip off the country calling code correctly.");
} catch (NumberParseException $e) {
$this->fail("Should not have thrown an exception: " . $e->getMessage());
}
$number->clear();
try {
$phoneNumber = "+6423456789";
$countryCallingCode = 64;
$numberToFill = "";
$this->assertEquals($countryCallingCode, $this->phoneUtil->maybeExtractCountryCode($phoneNumber, $metadata, $numberToFill, true, $number), "Did not extract country calling code " . $countryCallingCode . " correctly.");
$this->assertEquals(CountryCodeSource::FROM_NUMBER_WITH_PLUS_SIGN, $number->getCountryCodeSource(), "Did not figure out CountryCodeSource correctly");
} catch (NumberParseException $e) {
$this->fail("Should not have thrown an exception: " . $e->getMessage());
}
$number->clear();
try {
$phoneNumber = "+80012345678";
$countryCallingCode = 800;
$numberToFill = "";
$this->assertEquals($countryCallingCode, $this->phoneUtil->maybeExtractCountryCode($phoneNumber, $metadata, $numberToFill, true, $number), "Did not extract country calling code " . $countryCallingCode . " correctly.");
$this->assertEquals(CountryCodeSource::FROM_NUMBER_WITH_PLUS_SIGN, $number->getCountryCodeSource(), "Did not figure out CountryCodeSource correctly");
} catch (NumberParseException $e) {
$this->fail("Should not have thrown an exception: " . $e->getMessage());
}
$number->clear();
try {
$phoneNumber = "2345-6789";
$numberToFill = "";
$this->assertEquals(0, $this->phoneUtil->maybeExtractCountryCode($phoneNumber, $metadata, $numberToFill, true, $number), "Should not have extracted a country calling code - no international prefix present.");
$this->assertEquals(CountryCodeSource::FROM_DEFAULT_COUNTRY, $number->getCountryCodeSource(), "Did not figure out CountryCodeSource correctly");
} catch (NumberParseException $e) {
$this->fail("Should not have thrown an exception: " . $e->getMessage());
}
$number->clear();
try {
$phoneNumber = "0119991123456789";
$numberToFill = "";
$this->phoneUtil->maybeExtractCountryCode($phoneNumber, $metadata, $numberToFill, true, $number);
$this->fail("Should have thrown an exception, no valid country calling code present.");
} catch (NumberParseException $e) {
// Expected.
$this->assertEquals(NumberParseException::INVALID_COUNTRY_CODE, $e->getErrorType(), "Wrong error type stored in exception.");
}
$number->clear();
try {
$phoneNumber = "(1 610) 619 4466";
$countryCallingCode = 1;
$numberToFill = "";
$this->assertEquals($countryCallingCode, $this->phoneUtil->maybeExtractCountryCode($phoneNumber, $metadata, $numberToFill, true, $number), "Should have extracted the country calling code of the region passed in");
$this->assertEquals(CountryCodeSource::FROM_NUMBER_WITHOUT_PLUS_SIGN, $number->getCountryCodeSource(), "Did not figure out CountryCodeSource correctly");
} catch (NumberParseException $e) {
$this->fail("Should not have thrown an exception: " . $e->getMessage());
}
$number->clear();
try {
$phoneNumber = "(1 610) 619 4466";
$countryCallingCode = 1;
$numberToFill = "";
$this->assertEquals($countryCallingCode, $this->phoneUtil->maybeExtractCountryCode($phoneNumber, $metadata, $numberToFill, false, $number), "Should have extracted the country calling code of the region passed in");
$this->assertFalse($number->hasCountryCodeSource(), "Should not contain CountryCodeSource");
} catch (NumberParseException $e) {
$this->fail("Should not have thrown an exception: " . $e->getMessage());
}
$number->clear();
try {
$phoneNumber = "(1 610) 619 446";
$numberToFill = "";
$this->assertEquals(0, $this->phoneUtil->maybeExtractCountryCode($phoneNumber, $metadata, $numberToFill, false, $number), "Should not have extracted a country calling code - invalid number after extraction of uncertain country calling code.");
$this->assertFalse($number->hasCountryCodeSource(), "Should not contain CountryCodeSource");
} catch (NumberParseException $e) {
$this->fail("Should not have thrown an exception: " . $e->getMessage());
}
$number->clear();
try {
$phoneNumber = "(1 610) 619";
$numberToFill = "";
$this->assertEquals(0, $this->phoneUtil->maybeExtractCountryCode($phoneNumber, $metadata, $numberToFill, true, $number), "Should not have extracted a country calling code - too short number both before and after extraction of uncertain country calling code.");
$this->assertEquals(CountryCodeSource::FROM_DEFAULT_COUNTRY, $number->getCountryCodeSource(), "Did not figure out CountryCodeSource correctly");
} catch (NumberParseException $e) {
$this->fail("Should not have thrown an exception: " . $e->getMessage());
}
}