function _phone_libphonenumber in Phone 7.2
Creates and returns a libphonenumber phonenumber object.
Parameters
string $number: The raw phone number we are working with.
string $countrycode: The selected countrycode for this number.
string $extension: An extension number.
bool $allow_alpha: When set to TRUE, and $number contains alpha characters, i.e. is a vanity number, then retain the alpha formatting, and do not convert the number to its numeric equivalent.
Return value
array An array with two items, the $phoneutil object, and the parsed $phonenumber object.
Throws
libphonenumber\NumberParseException on error.
4 calls to _phone_libphonenumber()
- phone_libphonenumber_clean in includes/
phone.libphonenumber.inc - Cleans up phone number components for saving into the database.
- phone_libphonenumber_format in includes/
phone.libphonenumber.inc - Formats a phone number using libphonenumber.
- phone_libphonenumber_valid in includes/
phone.libphonenumber.inc - Validates a phone number with libphonenumber.
- _phone_migrate_phone_number in ./
phone.module - Helper function for migrate-type functions: convert a number from a single-entry number to country code, number, and extension.
File
- includes/
phone.libphonenumber.inc, line 28 - Provides integration functions with the libraries API and libphonenumber.
Code
function _phone_libphonenumber($number, $countrycode, $extension, $allow_alpha = FALSE) {
// Get the PhoneNumberUtil object instance.
$phoneutil = libphonenumber\PhoneNumberUtil::getInstance();
// If we don't allow alpha characters, then strip them here.
if (!$allow_alpha) {
$number = libphonenumber\PhoneNumberUtil::convertAlphaCharactersInNumber($number);
}
// Let libphonenumber handle the extension.
if (!empty($extension)) {
$number .= ';ext=' . $extension;
}
// Parse the number into a phonenumber object.
$phonenumber = $phoneutil
->parse($number, $countrycode, NULL, TRUE);
return array(
$phoneutil,
$phonenumber,
);
}