Improved resource id creation

This commit is contained in:
Michael 2018-02-20 10:02:07 +00:00
commit a3af6807ac
9 changed files with 23 additions and 37 deletions

View file

@ -854,11 +854,13 @@ function check_addons(App $a)
return;
}
function get_guid($size = 16, $prefix = "")
function get_guid($size = 16, $prefix = '')
{
if ($prefix == "") {
if (is_bool($prefix)) {
$prefix = '';
} elseif ($prefix == '') {
$a = get_app();
$prefix = hash("crc32", $a->get_hostname());
$prefix = hash('crc32', $a->get_hostname());
}
while (strlen($prefix) < ($size - 13)) {
@ -867,10 +869,10 @@ function get_guid($size = 16, $prefix = "")
if ($size >= 24) {
$prefix = substr($prefix, 0, $size - 22);
return(str_replace(".", "", uniqid($prefix, true)));
return str_replace('.', '', uniqid($prefix, true));
} else {
$prefix = substr($prefix, 0, max($size - 13, 0));
return(uniqid($prefix));
return uniqid($prefix);
}
}