|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the O2System Framework package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Steeve Andrian Salim |
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
|
13
|
|
|
|
|
14
|
|
|
namespace O2System\Security\Generators; |
|
15
|
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class Uuid |
|
20
|
|
|
* |
|
21
|
|
|
* UUID (Universally Unique Identifier) Generator. |
|
22
|
|
|
* A UUID is a 16-octet (128-bit) number. |
|
23
|
|
|
* In its canonical form, a UUID is represented by 32 hexadecimal digits, displayed in five groups separated by hyphens, |
|
24
|
|
|
* in the form 8-4-4-4-12 for a total of 36 characters (32 alphanumeric characters and four hyphens). |
|
25
|
|
|
* |
|
26
|
|
|
* @package O2System\Security\Generators |
|
27
|
|
|
*/ |
|
28
|
|
|
class Uuid |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Uuid::generate |
|
32
|
|
|
* |
|
33
|
|
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
|
|
public static function generate() |
|
36
|
|
|
{ |
|
37
|
|
|
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', |
|
38
|
|
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff), |
|
39
|
|
|
mt_rand(0, 0xffff), |
|
40
|
|
|
mt_rand(0, 0x0C2f) | 0x4000, |
|
41
|
|
|
mt_rand(0, 0x3fff) | 0x8000, |
|
42
|
|
|
mt_rand(0, 0x2Aff), mt_rand(0, 0xffD3), mt_rand(0, 0xff4B) |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
} |