|
1
|
|
|
<?php |
|
2
|
|
|
namespace Fwolf\Util\Uuid; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* UUID like common format |
|
6
|
|
|
* |
|
7
|
|
|
* Old UUID format: |
|
8
|
|
|
* |
|
9
|
|
|
* [timeLow]-[timeMid]-[custom1]-[custom2](part1/2) |
|
10
|
|
|
* -[custom2](part2/2)[random1][random2] |
|
11
|
|
|
* |
|
12
|
|
|
* timeLow: 8 chars, seconds in microtime, hex format. |
|
13
|
|
|
* timeMid: 4 chars, micro-second in microtime, plus 10000, hex format. |
|
14
|
|
|
* custom1: 4 chars, user defined, '0000' if empty, hex format suggested. |
|
15
|
|
|
* custom2: 8 chars, user defined, hex of user ip if empty, |
|
16
|
|
|
* and random hex string if user ip cannot get, hex format too. |
|
17
|
|
|
* random1: 4 chars, random string, hex format. |
|
18
|
|
|
* random2: 4 chars, random string, hex format. |
|
19
|
|
|
* |
|
20
|
|
|
* New UUID format move custom2(part2) to random part, parts are splitted |
|
21
|
|
|
* separator. |
|
22
|
|
|
* |
|
23
|
|
|
* @see http://us.php.net/uniqid |
|
24
|
|
|
* |
|
25
|
|
|
* @copyright Copyright 2008-2016 Fwolf |
|
26
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
27
|
|
|
*/ |
|
28
|
|
|
class Base16 extends AbstractTimeBasedUuidGenerator |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
const LENGTH = 36; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
const LENGTH_SECOND = 8; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
const LENGTH_MICROSECOND = 4; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
const LENGTH_GROUP = 4; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
const LENGTH_CUSTOM = 4; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
const LENGTH_RANDOM = 12; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
const LENGTH_CHECK_DIGIT = 0; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
*/ |
|
68
|
|
|
const SEPARATOR = '-'; |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritdoc} |
|
73
|
|
|
*/ |
|
74
|
|
|
public function explain($uuid) |
|
75
|
|
|
{ |
|
76
|
|
|
$explanation = parent::explain($uuid); |
|
77
|
|
|
|
|
78
|
|
|
$second = $explanation->getSecond(); |
|
79
|
|
|
$second = base_convert($second, 16, 10); |
|
80
|
|
|
$explanation->setSecond(date('Y-m-d H:i:s', $second)); |
|
81
|
|
|
|
|
82
|
|
|
$explanation->setMicrosecond( |
|
83
|
|
|
base_convert($explanation->getMicrosecond(), 16, 10) * 2 |
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
return $explanation; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|