1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-31 18:17:28 +01:00

Aggiunta retrocompatibilità Mpdf con PHP5.6

This commit is contained in:
loviuz 2018-11-28 12:28:33 +01:00 committed by GitHub
parent 3be1167971
commit e15c30cc48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -188,3 +188,55 @@ function datediff($interval, $datefrom, $dateto, $using_timestamps = false)
return $datediff;
}
/**
* Porting della funzione random_int() per rendere Mpdf retrocompatibile con PHP 5.6
*/
if (!function_exists('random_int')) {
function random_int($min, $max) {
if (!function_exists('mcrypt_create_iv')) {
trigger_error(
'mcrypt must be loaded for random_int to work',
E_USER_WARNING
);
return null;
}
if (!is_int($min) || !is_int($max)) {
trigger_error('$min and $max must be integer values', E_USER_NOTICE);
$min = (int)$min;
$max = (int)$max;
}
if ($min > $max) {
trigger_error('$max can\'t be lesser than $min', E_USER_WARNING);
return null;
}
$range = $counter = $max - $min;
$bits = 1;
while ($counter >>= 1) {
++$bits;
}
$bytes = (int)max(ceil($bits/8), 1);
$bitmask = pow(2, $bits) - 1;
if ($bitmask >= PHP_INT_MAX) {
$bitmask = PHP_INT_MAX;
}
do {
$result = hexdec(
bin2hex(
mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM)
)
) & $bitmask;
} while ($result > $range);
return $result + $min;
}
}