本文整理匯總了PHP中libphonenumber\PhoneNumberUtil::init方法的典型用法代碼示例。如果您正苦於以下問題:PHP PhoneNumberUtil::init方法的具體用法?PHP PhoneNumberUtil::init怎麽用?PHP PhoneNumberUtil::init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類libphonenumber\PhoneNumberUtil
的用法示例。
在下文中一共展示了PhoneNumberUtil::init方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getInstance
/**
* Gets a {@link PhoneNumberUtil} instance to carry out international phone number formatting,
* parsing, or validation. The instance is loaded with phone number metadata for a number of most
* commonly used regions.
*
* <p>The {@link PhoneNumberUtil} is implemented as a singleton. Therefore, calling getInstance
* multiple times will only result in one instance being created.
*
* @param string $baseFileLocation
* @param array|null $countryCallingCodeToRegionCodeMap
* @return PhoneNumberUtil instance
*/
public static function getInstance($baseFileLocation = self::META_DATA_FILE_PREFIX, array $countryCallingCodeToRegionCodeMap = null)
{
if ($countryCallingCodeToRegionCodeMap === null) {
$countryCallingCodeToRegionCodeMap = CountryCodeToRegionCodeMap::$countryCodeToRegionCodeMap;
}
if (self::$instance === null) {
self::$instance = new PhoneNumberUtil();
self::$instance->countryCallingCodeToRegionCodeMap = $countryCallingCodeToRegionCodeMap;
self::$instance->init($baseFileLocation);
self::initCapturingExtnDigits();
self::initExtnPatterns();
self::initAsciiDigitMappings();
self::initExtnPattern();
self::$PLUS_CHARS_PATTERN = "[" . self::PLUS_CHARS . "]+";
self::$SEPARATOR_PATTERN = "[" . self::VALID_PUNCTUATION . "]+";
self::$CAPTURING_DIGIT_PATTERN = "(" . self::DIGITS . ")";
self::$VALID_START_CHAR_PATTERN = "[" . self::PLUS_CHARS . self::DIGITS . "]";
self::$ALPHA_PHONE_MAPPINGS = self::$ALPHA_MAPPINGS + self::$asciiDigitMappings;
self::$DIALLABLE_CHAR_MAPPINGS = self::$asciiDigitMappings;
self::$DIALLABLE_CHAR_MAPPINGS[self::PLUS_SIGN] = self::PLUS_SIGN;
self::$DIALLABLE_CHAR_MAPPINGS['*'] = '*';
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS = array();
// Put (lower letter -> upper letter) and (upper letter -> upper letter) mappings.
foreach (self::$ALPHA_MAPPINGS as $c => $value) {
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS[strtolower($c)] = $c;
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS[$c] = $c;
}
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS += self::$asciiDigitMappings;
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["-"] = '-';
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["-"] = '-';
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["‐"] = '-';
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["‑"] = '-';
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["‒"] = '-';
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["–"] = '-';
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["—"] = '-';
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["―"] = '-';
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["−"] = '-';
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["/"] = "/";
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["/"] = "/";
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS[" "] = " ";
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS[" "] = " ";
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS[""] = " ";
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["."] = ".";
self::$ALL_PLUS_NUMBER_GROUPING_SYMBOLS["."] = ".";
self::$MIN_LENGTH_PHONE_NUMBER_PATTERN = "[" . self::DIGITS . "]{" . self::MIN_LENGTH_FOR_NSN . "}";
self::$VALID_PHONE_NUMBER = "[" . self::PLUS_CHARS . "]*(?:[" . self::VALID_PUNCTUATION . self::STAR_SIGN . "]*[" . self::DIGITS . "]){3,}[" . self::VALID_PUNCTUATION . self::STAR_SIGN . self::VALID_ALPHA . self::DIGITS . "]*";
self::$VALID_PHONE_NUMBER_PATTERN = "%^" . self::$MIN_LENGTH_PHONE_NUMBER_PATTERN . "\$|^" . self::$VALID_PHONE_NUMBER . "(?:" . self::$EXTN_PATTERNS_FOR_PARSING . ")?%" . self::REGEX_FLAGS;
self::$UNWANTED_END_CHAR_PATTERN = "[^" . self::DIGITS . self::VALID_ALPHA . "#]+\$";
self::$MOBILE_TOKEN_MAPPINGS = array();
self::$MOBILE_TOKEN_MAPPINGS['52'] = "1";
self::$MOBILE_TOKEN_MAPPINGS['54'] = "9";
self::loadNumericCharacters();
}
return self::$instance;
}