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