Skip to content

Commit

Permalink
Added helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
libern committed Sep 8, 2016
1 parent b918a2e commit b03cece
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion src/Someline/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,58 @@ function is_jwt_token_valid_for_refresh($token, $allowExpireRefresh = false)
return $is_jwt_token_valid_for_refresh;
}

}
}

if (!function_exists('phone_parse')) {

/**
* @param string $phone_number
* @param string $country_code An ISO 3166-1 two letter country code
* @return null|\libphonenumber\PhoneNumber
*/
function phone_parse($phone_number, $country_code)
{
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
try {
$phoneNumberProto = $phoneUtil->parseAndKeepRawInput($phone_number, $country_code);
return $phoneNumberProto;
} catch (\libphonenumber\NumberParseException $e) {
return null;
}
}

}

if (!function_exists('phone_model_from')) {

/**
* @param string $phone_number
* @param string $country_code An ISO 3166-1 two letter country code
* @return \Someline\Model\Basic\PhoneNumberModel
*/
function phone_model_from($phone_number, $country_code)
{
return new \Someline\Model\Basic\PhoneNumberModel($phone_number, $country_code);
}

}

if (!function_exists('ip_to_country_iso_code')) {

function ip_to_country_iso_code($ip = null, $default_iso_code = 'US')
{
if (empty($ip)) {
$ip = smart_get_client_ip();
}

$location = \GeoIP::getLocation($ip);

// check if NOT returned default
if ($location['default'] === false && !empty($location['isoCode'])) {
return $location['isoCode'];
} else {
return $default_iso_code;
}
}

}

0 comments on commit b03cece

Please sign in to comment.