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


PHP PhoneNumber::equals方法代碼示例

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


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

示例1: isNumberMatch


//.........這裏部分代碼省略.........
                             $firstNumberProto = new PhoneNumber();
                             $secondNumberProto = new PhoneNumber();
                             $this->parseHelper($firstNumberIn, null, false, false, $firstNumberProto);
                             $this->parseHelper($secondNumberIn, null, false, false, $secondNumberProto);
                             return $this->isNumberMatch($firstNumberProto, $secondNumberProto);
                         } catch (NumberParseException $e3) {
                             // Fall through and return MatchType::NOT_A_NUMBER
                         }
                     }
                 }
             }
         }
         return MatchType::NOT_A_NUMBER;
     }
     if ($firstNumberIn instanceof PhoneNumber && is_string($secondNumberIn)) {
         // First see if the second number has an implicit country calling code, by attempting to parse
         // it.
         try {
             $secondNumberAsProto = $this->parse($secondNumberIn, self::UNKNOWN_REGION);
             return $this->isNumberMatch($firstNumberIn, $secondNumberAsProto);
         } catch (NumberParseException $e) {
             if ($e->getErrorType() === NumberParseException::INVALID_COUNTRY_CODE) {
                 // The second number has no country calling code. EXACT_MATCH is no longer possible.
                 // We parse it as if the region was the same as that for the first number, and if
                 // EXACT_MATCH is returned, we replace this with NSN_MATCH.
                 $firstNumberRegion = $this->getRegionCodeForCountryCode($firstNumberIn->getCountryCode());
                 try {
                     if ($firstNumberRegion != self::UNKNOWN_REGION) {
                         $secondNumberWithFirstNumberRegion = $this->parse($secondNumberIn, $firstNumberRegion);
                         $match = $this->isNumberMatch($firstNumberIn, $secondNumberWithFirstNumberRegion);
                         if ($match === MatchType::EXACT_MATCH) {
                             return MatchType::NSN_MATCH;
                         }
                         return $match;
                     } else {
                         // If the first number didn't have a valid country calling code, then we parse the
                         // second number without one as well.
                         $secondNumberProto = new PhoneNumber();
                         $this->parseHelper($secondNumberIn, null, false, false, $secondNumberProto);
                         return $this->isNumberMatch($firstNumberIn, $secondNumberProto);
                     }
                 } catch (NumberParseException $e2) {
                     // Fall-through to return NOT_A_NUMBER.
                 }
             }
         }
     }
     if ($firstNumberIn instanceof PhoneNumber && $secondNumberIn instanceof PhoneNumber) {
         // Make copies of the phone number so that the numbers passed in are not edited.
         $firstNumber = new PhoneNumber();
         $firstNumber->mergeFrom($firstNumberIn);
         $secondNumber = new PhoneNumber();
         $secondNumber->mergeFrom($secondNumberIn);
         // First clear raw_input, country_code_source and preferred_domestic_carrier_code fields and any
         // empty-string extensions so that we can use the proto-buffer equality method.
         $firstNumber->clearRawInput();
         $firstNumber->clearCountryCodeSource();
         $firstNumber->clearPreferredDomesticCarrierCode();
         $secondNumber->clearRawInput();
         $secondNumber->clearCountryCodeSource();
         $secondNumber->clearPreferredDomesticCarrierCode();
         if ($firstNumber->hasExtension() && mb_strlen($firstNumber->getExtension()) === 0) {
             $firstNumber->clearExtension();
         }
         if ($secondNumber->hasExtension() && mb_strlen($secondNumber->getExtension()) === 0) {
             $secondNumber->clearExtension();
         }
         // Early exit if both had extensions and these are different.
         if ($firstNumber->hasExtension() && $secondNumber->hasExtension() && $firstNumber->getExtension() != $secondNumber->getExtension()) {
             return MatchType::NO_MATCH;
         }
         $firstNumberCountryCode = $firstNumber->getCountryCode();
         $secondNumberCountryCode = $secondNumber->getCountryCode();
         // Both had country_code specified.
         if ($firstNumberCountryCode != 0 && $secondNumberCountryCode != 0) {
             if ($firstNumber->equals($secondNumber)) {
                 return MatchType::EXACT_MATCH;
             } elseif ($firstNumberCountryCode == $secondNumberCountryCode && $this->isNationalNumberSuffixOfTheOther($firstNumber, $secondNumber)) {
                 // A SHORT_NSN_MATCH occurs if there is a difference because of the presence or absence of
                 // an 'Italian leading zero', the presence or absence of an extension, or one NSN being a
                 // shorter variant of the other.
                 return MatchType::SHORT_NSN_MATCH;
             }
             // This is not a match.
             return MatchType::NO_MATCH;
         }
         // Checks cases where one or both country_code fields were not specified. To make equality
         // checks easier, we first set the country_code fields to be equal.
         $firstNumber->setCountryCode($secondNumberCountryCode);
         // If all else was the same, then this is an NSN_MATCH.
         if ($firstNumber->equals($secondNumber)) {
             return MatchType::NSN_MATCH;
         }
         if ($this->isNationalNumberSuffixOfTheOther($firstNumber, $secondNumber)) {
             return MatchType::SHORT_NSN_MATCH;
         }
         return MatchType::NO_MATCH;
     }
     return MatchType::NOT_A_NUMBER;
 }
開發者ID:kasirye,項目名稱:faveo-helpdesk,代碼行數:101,代碼來源:PhoneNumberUtil.php


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