diff options
| author | spiderr <spiderr@bitweaver.org> | 2023-11-19 16:32:18 -0500 |
|---|---|---|
| committer | spiderr <spiderr@bitweaver.org> | 2023-11-19 16:32:18 -0500 |
| commit | 1c61e3efde69e6095eb23bf09989f2530230a312 (patch) | |
| tree | 0d7bd82bf26979f14d8a1a68a7ebdf1e972554dd /smartyplugins | |
| parent | 5efd4edd850f28c6732541a0e647c2f22c914c73 (diff) | |
| download | themes-1c61e3efde69e6095eb23bf09989f2530230a312.tar.gz themes-1c61e3efde69e6095eb23bf09989f2530230a312.tar.bz2 themes-1c61e3efde69e6095eb23bf09989f2530230a312.zip | |
error handling to telephone_e164
Diffstat (limited to 'smartyplugins')
| -rw-r--r-- | smartyplugins/modifier.telephone_e164.php | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/smartyplugins/modifier.telephone_e164.php b/smartyplugins/modifier.telephone_e164.php index f53afc6..5c37433 100644 --- a/smartyplugins/modifier.telephone_e164.php +++ b/smartyplugins/modifier.telephone_e164.php @@ -9,26 +9,33 @@ * smarty_modifier_telelphone_e164 */ function smarty_modifier_telephone_e164( $pTelephoneNumber, $pCountryCodeIso2='US' ) { - $ret = $pTelephoneNumber; + if( $ret = $pTelephoneNumber ) { - global $gPhoneNumberUtil; - if( empty( $gPhoneNumberUtil ) ) { - spl_autoload_register(function ($class) { - // replace namespace separators with directory separators in the relative - // class name, append with .php - $class_path = str_replace('\\', '/', $class); - - $file = EXTERNAL_LIBS_PATH . $class_path . '.php'; + global $gPhoneNumberUtil; + if( empty( $gPhoneNumberUtil ) ) { + spl_autoload_register(function ($class) { + // replace namespace separators with directory separators in the relative + // class name, append with .php + $class_path = str_replace('\\', '/', $class); + + $file = EXTERNAL_LIBS_PATH . $class_path . '.php'; - // if the file exists, require it - if (file_exists($file)) { - require_once( $file ); + // if the file exists, require it + if (file_exists($file)) { + require_once( $file ); + } + }); + $gPhoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance(); + } + if( is_object( $gPhoneNumberUtil ) ) { + try { + if( $parsedNumber = $gPhoneNumberUtil->parse( $pTelephoneNumber, $pCountryCodeIso2 ) ) { + $ret = $gPhoneNumberUtil->format( $parsedNumber, \libphonenumber\PhoneNumberFormat::E164 ); + } + } catch( Exception $e ) { + bit_error_log( 'telephone_e164 failed: '.$pCountryCodeIso2.' '.$pTelephoneNumber ); } - }); - $gPhoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance(); - } - if( is_object( $gPhoneNumberUtil ) && ($parsedNumber = $gPhoneNumberUtil->parse( $pTelephoneNumber, $pCountryCodeIso2 ) ) ) { - $ret = $gPhoneNumberUtil->format( $parsedNumber, \libphonenumber\PhoneNumberFormat::E164 ); + } } return $ret; } |
