forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.php
More file actions
33 lines (29 loc) · 884 Bytes
/
Util.php
File metadata and controls
33 lines (29 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
declare(strict_types=1);
namespace Hestia\System;
class Util
{
/*
* Method from: https://stackoverflow.com/a/15575293
* https://stackoverflow.com/questions/1091107/how-to-join-filesystem-path-strings-in-php
*/
public static function join_paths()
{
$paths = array();
foreach (func_get_args() as $arg) {
if ($arg !== '') {
$paths[] = $arg;
}
}
return preg_replace('#/+#', '/', join('/', $paths));
}
public static function generate_string(int $length = 16)
{
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@|#[]$%^&*() _-=+{}:;<>?,./';
$random_string = '';
for ($i = 0; $i < $length; $i++) {
$random_string .= $chars[random_int(0, strlen($chars) - 1)];
}
return $random_string;
}
}