forked from ammmze/DeployMint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeployMintTools.php
53 lines (45 loc) · 1.71 KB
/
DeployMintTools.php
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
class DeployMintTools
{
public static function mexec($cmd, $cwd = './', $env = null, $timeout = null)
{ // TODO: Put this somewhere it can be used by all DeployMint classes
$dspec = array(
0 => array("pipe", "r"), //stdin
1 => array("pipe", "w"), //stdout
2 => array("pipe", "w") //stderr
);
$proc = proc_open($cmd, $dspec, $pipes, $cwd);
if ($timeout != null) {
stream_set_timeout($pipes[1], $timeout);
stream_set_timeout($pipes[2], $timeout);
}
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
$ret = proc_close($proc);
return $stdout . $stderr;
}
public static function generateUUID()
{
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
// 16 bits for "time_mid"
mt_rand( 0, 0xffff ),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand( 0, 0x0fff ) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand( 0, 0x3fff ) | 0x8000,
// 48 bits for "node"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}
public static function isUUID($str)
{
return preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $str);
}
}