@@ 75-85 (lines=11) @@ | ||
72 | ||
73 | public static function uuid($type = 4, $namespace = '', $name = '') { |
|
74 | switch ($type) { |
|
75 | case 3:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' . |
|
76 | '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) { |
|
77 | return false; |
|
78 | } |
|
79 | ||
80 | $nhex = str_replace(array('-', '{', '}'), '', $namespace); |
|
81 | $nstr = '';for ($i = 0; $i < strlen($nhex); $i += 2) { |
|
82 | $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1])); |
|
83 | } |
|
84 | ||
85 | $hash = md5($nstr . $name); |
|
86 | return sprintf('%08s-%04s-%04x-%04x-%12s', |
|
87 | substr($hash, 0, 8), substr($hash, 8, 4), |
|
88 | (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000, |
|
@@ 91-101 (lines=11) @@ | ||
88 | (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000, |
|
89 | (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000, |
|
90 | substr($hash, 20, 12)); |
|
91 | case 5:if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' . |
|
92 | '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) { |
|
93 | return false; |
|
94 | } |
|
95 | ||
96 | $nhex = str_replace(array('-', '{', '}'), '', $namespace); |
|
97 | $nstr = '';for ($i = 0; $i < strlen($nhex); $i += 2) { |
|
98 | $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1])); |
|
99 | } |
|
100 | ||
101 | $hash = sha1($nstr . $name); |
|
102 | return sprintf('%08s-%04s-%04x-%04x-%12s', |
|
103 | substr($hash, 0, 8), substr($hash, 8, 4), |
|
104 | (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000, |