get rid of more functions

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-20 12:38:18 +01:00
parent f263175802
commit 5888927239
53 changed files with 639 additions and 858 deletions

View File

@@ -37,6 +37,34 @@ class PhpHelper
}
}
/**
* Function randomStr
*
* generate a pseudo-random string of bytes
*
* @param int $length
*
* @return string
*/
public static function randomStr($length)
{
if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
return random_bytes($length);
} elseif (function_exists('openssl_random_pseudo_bytes')) {
return openssl_random_pseudo_bytes($length);
} else {
$pr_bits = '';
$fp = @fopen('/dev/urandom', 'rb');
if ($fp !== false) {
$pr_bits .= @fread($fp, $length);
@fclose($fp);
} else {
$pr_bits = substr(rand(time(), getrandmax()) . rand(time(), getrandmax()), 0, $length);
}
return $pr_bits;
}
}
/**
* Return human readable sizes
*
@@ -46,8 +74,9 @@ class PhpHelper
* maximum unit
* @param string $system
* 'si' for SI, 'bi' for binary prefixes
*
* @param string
*
* @param
* string
*/
public static function size_readable($size, $max = null, $system = 'si', $retstring = '%01.2f %s')
{