本文整理汇总了PHP中PhoneNumber::mergeFrom方法的典型用法代码示例。如果您正苦于以下问题:PHP PhoneNumber::mergeFrom方法的具体用法?PHP PhoneNumber::mergeFrom怎么用?PHP PhoneNumber::mergeFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhoneNumber
的用法示例。
在下文中一共展示了PhoneNumber::mergeFrom方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFormatNumberWithExtension
public function testFormatNumberWithExtension()
{
$nzNumber = new PhoneNumber();
$nzNumber->mergeFrom(self::$nzNumber)->setExtension("1234");
// Uses default extension prefix:
$this->assertEquals("03-331 6005 ext. 1234", $this->phoneUtil->format($nzNumber, PhoneNumberFormat::NATIONAL));
// Uses RFC 3966 syntax.
$this->assertEquals("+64-3-331-6005;ext=1234", $this->phoneUtil->format($nzNumber, PhoneNumberFormat::RFC3966));
// Extension prefix overridden in the territory information for the US:
$usNumberWithExtension = new PhoneNumber();
$usNumberWithExtension->mergeFrom(self::$usNumber)->setExtension("4567");
$this->assertEquals("650 253 0000 extn. 4567", $this->phoneUtil->format($usNumberWithExtension, PhoneNumberFormat::NATIONAL));
}
示例2: truncateTooLongNumber
/**
* Attempts to extract a valid number from a phone number that is too long to be valid, and resets
* the PhoneNumber object passed in to that valid version. If no valid number could be extracted,
* the PhoneNumber object passed in will not be modified.
* @param PhoneNumber $number a PhoneNumber object which contains a number that is too long to be valid.
* @return boolean true if a valid phone number can be successfully extracted.
*/
public function truncateTooLongNumber(PhoneNumber $number)
{
if ($this->isValidNumber($number)) {
return true;
}
$numberCopy = new PhoneNumber();
$numberCopy->mergeFrom($number);
$nationalNumber = $number->getNationalNumber();
do {
$nationalNumber = floor($nationalNumber / 10);
$numberCopy->setNationalNumber($nationalNumber);
if ($this->isPossibleNumberWithReason($numberCopy) == ValidationResult::TOO_SHORT || $nationalNumber == 0) {
return false;
}
} while (!$this->isValidNumber($numberCopy));
$number->setNationalNumber($nationalNumber);
return true;
}
示例3: formatNumberForMobileDialing
/**
* Returns a number formatted in such a way that it can be dialed from a mobile phone in a
* specific region. If the number cannot be reached from the region (e.g. some countries block
* toll-free numbers from being called outside of the country), the method returns an empty
* string.
*
* @param PhoneNumber $number the phone number to be formatted
* @param String $regionCallingFrom the region where the call is being placed
* @param boolean $withFormatting whether the number should be returned with formatting symbols, such as
* spaces and dashes.
* @return String the formatted phone number
*/
public function formatNumberForMobileDialing(PhoneNumber $number, $regionCallingFrom, $withFormatting)
{
$countryCallingCode = $number->getCountryCode();
if (!$this->hasValidCountryCallingCode($countryCallingCode)) {
return $number->hasRawInput() ? $number->getRawInput() : "";
}
// Clear the extension, as that part cannot normally be dialed together with the main number.
$numberNoExt = new PhoneNumber();
$numberNoExt->mergeFrom($number)->clearExtension();
$numberType = $this->getNumberType($numberNoExt);
$regionCode = $this->getRegionCodeForCountryCode($countryCallingCode);
if ($regionCode == "CO" && $regionCallingFrom == "CO") {
if ($numberType == PhoneNumberType::FIXED_LINE) {
$formattedNumber = $this->formatNationalNumberWithCarrierCode($numberNoExt, self::COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX);
} else {
// E164 doesn't work at all when dialing within Colombia.
$formattedNumber = $this->format($numberNoExt, PhoneNumberFormat::NATIONAL);
}
} else {
if ($regionCode == "PE" && $regionCallingFrom == "PE") {
// In Peru, numbers cannot be dialled using E164 format from a mobile phone for Movistar.
// Instead they must be dialled in national format.
$formattedNumber = $this->format($numberNoExt, PhoneNumberFormat::NATIONAL);
} else {
if ($regionCode == "AE" && $regionCallingFrom == "AE" && $numberType == PhoneNumberType::UAN) {
// In the United Arab Emirates, numbers with the prefix 600 (UAN numbers) cannot be dialled
// using E164 format. Instead they must be dialled in national format.
$formattedNumber = $this->format($numberNoExt, PhoneNumberFormat::NATIONAL);
} else {
if ($regionCode == "BR" && $regionCallingFrom == "BR" && ($numberType == PhoneNumberType::FIXED_LINE || $numberType == PhoneNumberType::MOBILE || $numberType == PhoneNumberType::FIXED_LINE_OR_MOBILE)) {
$formattedNumber = $numberNoExt->hasPreferredDomesticCarrierCode() ? $this->formatNationalNumberWithPreferredCarrierCode($numberNoExt, "") : "";
} else {
if ($this->canBeInternationallyDialled($numberNoExt)) {
return $withFormatting ? $this->format($numberNoExt, PhoneNumberFormat::INTERNATIONAL) : $this->format($numberNoExt, PhoneNumberFormat::E164);
} else {
$formattedNumber = $regionCallingFrom == $regionCode ? $this->format($numberNoExt, PhoneNumberFormat::NATIONAL) : "";
}
}
}
}
}
return $withFormatting ? $formattedNumber : $this->normalizeHelper($formattedNumber, self::$DIALLABLE_CHAR_MAPPINGS, true);
}