1 | <?php |
||
15 | class Variant |
||
16 | { |
||
17 | const NCS = 0; |
||
18 | const RFC4122 = 1; |
||
19 | const MICROSOFT = 2; |
||
20 | const FUTURE = 3; |
||
21 | const OTHER = 4; |
||
22 | |||
23 | /** |
||
24 | * Named variants |
||
25 | * |
||
26 | * 'other' not named, because only used as fallback value |
||
27 | * |
||
28 | * @var array<int,string> |
||
29 | */ |
||
30 | public static $variants = [ |
||
31 | self::NCS => 'ncs', |
||
32 | self::RFC4122 => 'rfc4122', |
||
33 | self::MICROSOFT => 'microsoft', |
||
34 | self::FUTURE => 'future' |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * The mask for the variant is established as a single byte, and an int |
||
39 | * from 1-8 that says how many bits of the byte value are considered |
||
40 | * insignificant (the RFC says the multiplexing differs between variants) |
||
41 | * |
||
42 | * That is, if the variant uses the first 3 bits of the multiplexed value, |
||
43 | * the int value will be 8 - 3 = 5. This means shifting the multiplexed value |
||
44 | * left by five bits will retain only the variant information. |
||
45 | * |
||
46 | * @var array<int,array> |
||
47 | */ |
||
48 | protected $mask = [ |
||
49 | self::NCS => [0x00, 7], |
||
50 | self::RFC4122 => [0x80, 6], |
||
51 | self::MICROSOFT => [0xC0, 5], |
||
52 | self::FUTURE => [0xE0, 5] |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * @var Uuid |
||
57 | */ |
||
58 | protected $uuid; |
||
59 | |||
60 | /** |
||
61 | * @param Uuid $uuid |
||
62 | */ |
||
63 | 4 | public function __construct(Uuid $uuid) |
|
67 | |||
68 | /** |
||
69 | * @return int |
||
70 | */ |
||
71 | 3 | public function get() |
|
87 | |||
88 | /** |
||
89 | * @param int $variant See self::* formats |
||
90 | */ |
||
91 | 2 | public function set($variant) |
|
105 | |||
106 | /** |
||
107 | * Get a single byte from the UUID containing the variant in the high bits |
||
108 | * |
||
109 | * We're assuming here that the variant will only ever be multiplexed into |
||
110 | * a single byte of the clock_seq field. (True of all currently known |
||
111 | * variants) |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | 3 | protected function getVariantByte() |
|
120 | |||
121 | /** |
||
122 | * @param string $byte A single byte |
||
123 | * @return string |
||
124 | */ |
||
125 | 1 | protected function setVariantByte($byte) |
|
131 | } |
||
132 |