18
18
*/
19
19
final class Uuid
20
20
{
21
- const UUID_VARIANT_NCS = 0 ;
22
- const UUID_VARIANT_DCE = 1 ;
23
- const UUID_VARIANT_MICROSOFT = 2 ;
24
- const UUID_VARIANT_OTHER = 3 ;
25
- const UUID_TYPE_DEFAULT = 0 ;
26
- const UUID_TYPE_TIME = 1 ;
27
- const UUID_TYPE_MD5 = 3 ;
28
- const UUID_TYPE_DCE = 4 ; // Deprecated alias
29
- const UUID_TYPE_NAME = 1 ; // Deprecated alias
30
- const UUID_TYPE_RANDOM = 4 ;
31
- const UUID_TYPE_SHA1 = 5 ;
32
- const UUID_TYPE_NULL = -1 ;
33
- const UUID_TYPE_INVALID = -42 ;
21
+ public const UUID_VARIANT_NCS = 0 ;
22
+ public const UUID_VARIANT_DCE = 1 ;
23
+ public const UUID_VARIANT_MICROSOFT = 2 ;
24
+ public const UUID_VARIANT_OTHER = 3 ;
25
+ public const UUID_TYPE_DEFAULT = 0 ;
26
+ public const UUID_TYPE_TIME = 1 ;
27
+ public const UUID_TYPE_MD5 = 3 ;
28
+ public const UUID_TYPE_DCE = 4 ; // Deprecated alias
29
+ public const UUID_TYPE_NAME = 1 ; // Deprecated alias
30
+ public const UUID_TYPE_RANDOM = 4 ;
31
+ public const UUID_TYPE_SHA1 = 5 ;
32
+ public const UUID_TYPE_NULL = -1 ;
33
+ public const UUID_TYPE_INVALID = -42 ;
34
34
35
35
// https://tools.ietf.org/html/rfc4122#section-4.1.4
36
36
// 0x01b21dd213814000 is the number of 100-ns intervals between the
37
37
// UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
38
- const TIME_OFFSET_INT = 0x01b21dd213814000 ;
39
- const TIME_OFFSET_BIN = "\x01\xb2\x1d\xd2\x13\x81\x40\x00" ;
40
- const TIME_OFFSET_COM = "\xfe\x4d\xe2\x2d\xec\x7e\xc0\x00" ;
38
+ public const TIME_OFFSET_INT = 0x01b21dd213814000 ;
39
+ public const TIME_OFFSET_BIN = "\x01\xb2\x1d\xd2\x13\x81\x40\x00" ;
40
+ public const TIME_OFFSET_COM = "\xfe\x4d\xe2\x2d\xec\x7e\xc0\x00" ;
41
41
42
- public static function uuid_create ($ uuid_type = UUID_TYPE_DEFAULT )
42
+ public static function uuid_create ($ uuid_type = \ UUID_TYPE_DEFAULT )
43
43
{
44
- if (!\ is_numeric ($ uuid_type ) && null !== $ uuid_type ) {
45
- trigger_error (sprintf ('uuid_create() expects parameter 1 to be int, %s given ' , \gettype ($ uuid_type )), E_USER_WARNING );
44
+ if (!is_numeric ($ uuid_type ) && null !== $ uuid_type ) {
45
+ trigger_error (sprintf ('uuid_create() expects parameter 1 to be int, %s given ' , \gettype ($ uuid_type )), \ E_USER_WARNING );
46
46
47
47
return null ;
48
48
}
@@ -56,7 +56,7 @@ public static function uuid_create($uuid_type = UUID_TYPE_DEFAULT)
56
56
case self ::UUID_TYPE_DEFAULT :
57
57
return self ::uuid_generate_random ();
58
58
default :
59
- trigger_error (sprintf ("Unknown/invalid UUID type '%d' requested, using default type instead " , $ uuid_type ), E_USER_WARNING );
59
+ trigger_error (sprintf ("Unknown/invalid UUID type '%d' requested, using default type instead " , $ uuid_type ), \ E_USER_WARNING );
60
60
61
61
return self ::uuid_generate_random ();
62
62
}
@@ -65,13 +65,13 @@ public static function uuid_create($uuid_type = UUID_TYPE_DEFAULT)
65
65
public static function uuid_generate_md5 ($ uuid_ns , $ name )
66
66
{
67
67
if (!\is_string ($ uuid_ns = self ::toString ($ uuid_ns ))) {
68
- trigger_error (sprintf ('uuid_generate_md5() expects parameter 1 to be string, %s given ' , \gettype ($ uuid_ns )), E_USER_WARNING );
68
+ trigger_error (sprintf ('uuid_generate_md5() expects parameter 1 to be string, %s given ' , \gettype ($ uuid_ns )), \ E_USER_WARNING );
69
69
70
70
return null ;
71
71
}
72
72
73
73
if (!\is_string ($ name = self ::toString ($ name ))) {
74
- trigger_error (sprintf ('uuid_generate_md5() expects parameter 2 to be string, %s given ' , \gettype ($ name )), E_USER_WARNING );
74
+ trigger_error (sprintf ('uuid_generate_md5() expects parameter 2 to be string, %s given ' , \gettype ($ name )), \ E_USER_WARNING );
75
75
76
76
return null ;
77
77
}
@@ -106,13 +106,13 @@ public static function uuid_generate_md5($uuid_ns, $name)
106
106
public static function uuid_generate_sha1 ($ uuid_ns , $ name )
107
107
{
108
108
if (!\is_string ($ uuid_ns = self ::toString ($ uuid_ns ))) {
109
- trigger_error (sprintf ('uuid_generate_sha1() expects parameter 1 to be string, %s given ' , \gettype ($ uuid_ns )), E_USER_WARNING );
109
+ trigger_error (sprintf ('uuid_generate_sha1() expects parameter 1 to be string, %s given ' , \gettype ($ uuid_ns )), \ E_USER_WARNING );
110
110
111
111
return null ;
112
112
}
113
113
114
114
if (!\is_string ($ name = self ::toString ($ name ))) {
115
- trigger_error (sprintf ('uuid_generate_sha1() expects parameter 2 to be string, %s given ' , \gettype ($ name )), E_USER_WARNING );
115
+ trigger_error (sprintf ('uuid_generate_sha1() expects parameter 2 to be string, %s given ' , \gettype ($ name )), \ E_USER_WARNING );
116
116
117
117
return null ;
118
118
}
@@ -149,7 +149,7 @@ public static function uuid_generate_sha1($uuid_ns, $name)
149
149
public static function uuid_is_valid ($ uuid )
150
150
{
151
151
if (!\is_string ($ uuid = self ::toString ($ uuid ))) {
152
- trigger_error (sprintf ('uuid_is_valid() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), E_USER_WARNING );
152
+ trigger_error (sprintf ('uuid_is_valid() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), \ E_USER_WARNING );
153
153
154
154
return null ;
155
155
}
@@ -160,13 +160,13 @@ public static function uuid_is_valid($uuid)
160
160
public static function uuid_compare ($ uuid1 , $ uuid2 )
161
161
{
162
162
if (!\is_string ($ uuid1 = self ::toString ($ uuid1 ))) {
163
- trigger_error (sprintf ('uuid_compare() expects parameter 1 to be string, %s given ' , \gettype ($ uuid1 )), E_USER_WARNING );
163
+ trigger_error (sprintf ('uuid_compare() expects parameter 1 to be string, %s given ' , \gettype ($ uuid1 )), \ E_USER_WARNING );
164
164
165
165
return null ;
166
166
}
167
167
168
168
if (!\is_string ($ uuid2 = self ::toString ($ uuid2 ))) {
169
- trigger_error (sprintf ('uuid_compare() expects parameter 2 to be string, %s given ' , \gettype ($ uuid2 )), E_USER_WARNING );
169
+ trigger_error (sprintf ('uuid_compare() expects parameter 2 to be string, %s given ' , \gettype ($ uuid2 )), \ E_USER_WARNING );
170
170
171
171
return null ;
172
172
}
@@ -193,7 +193,7 @@ public static function uuid_compare($uuid1, $uuid2)
193
193
public static function uuid_is_null ($ uuid )
194
194
{
195
195
if (!\is_string ($ uuid = self ::toString ($ uuid ))) {
196
- trigger_error (sprintf ('uuid_is_null() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), E_USER_WARNING );
196
+ trigger_error (sprintf ('uuid_is_null() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), \ E_USER_WARNING );
197
197
198
198
return null ;
199
199
}
@@ -207,7 +207,7 @@ public static function uuid_is_null($uuid)
207
207
public static function uuid_type ($ uuid )
208
208
{
209
209
if (!\is_string ($ uuid = self ::toString ($ uuid ))) {
210
- trigger_error (sprintf ('uuid_type() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), E_USER_WARNING );
210
+ trigger_error (sprintf ('uuid_type() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), \ E_USER_WARNING );
211
211
212
212
return null ;
213
213
}
@@ -230,7 +230,7 @@ public static function uuid_type($uuid)
230
230
public static function uuid_variant ($ uuid )
231
231
{
232
232
if (!\is_string ($ uuid = self ::toString ($ uuid ))) {
233
- trigger_error (sprintf ('uuid_variant() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), E_USER_WARNING );
233
+ trigger_error (sprintf ('uuid_variant() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), \ E_USER_WARNING );
234
234
235
235
return null ;
236
236
}
@@ -263,7 +263,7 @@ public static function uuid_variant($uuid)
263
263
public static function uuid_time ($ uuid )
264
264
{
265
265
if (!\is_string ($ uuid = self ::toString ($ uuid ))) {
266
- trigger_error (sprintf ('uuid_time() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), E_USER_WARNING );
266
+ trigger_error (sprintf ('uuid_time() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), \ E_USER_WARNING );
267
267
268
268
return null ;
269
269
}
@@ -282,7 +282,7 @@ public static function uuid_time($uuid)
282
282
return intdiv (hexdec ($ parsed ['time ' ]) - self ::TIME_OFFSET_INT , 10000000 );
283
283
}
284
284
285
- $ time = str_pad (hex2bin ($ parsed ['time ' ]), 8 , "\0" , STR_PAD_LEFT );
285
+ $ time = str_pad (hex2bin ($ parsed ['time ' ]), 8 , "\0" , \ STR_PAD_LEFT );
286
286
$ time = self ::binaryAdd ($ time , self ::TIME_OFFSET_COM );
287
287
$ time [0 ] = $ time [0 ] & "\x7F" ;
288
288
@@ -292,7 +292,7 @@ public static function uuid_time($uuid)
292
292
public static function uuid_mac ($ uuid )
293
293
{
294
294
if (!\is_string ($ uuid = self ::toString ($ uuid ))) {
295
- trigger_error (sprintf ('uuid_mac() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), E_USER_WARNING );
295
+ trigger_error (sprintf ('uuid_mac() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), \ E_USER_WARNING );
296
296
297
297
return null ;
298
298
}
@@ -313,7 +313,7 @@ public static function uuid_mac($uuid)
313
313
public static function uuid_parse ($ uuid )
314
314
{
315
315
if (!\is_string ($ uuid = self ::toString ($ uuid ))) {
316
- trigger_error (sprintf ('uuid_parse() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), E_USER_WARNING );
316
+ trigger_error (sprintf ('uuid_parse() expects parameter 1 to be string, %s given ' , \gettype ($ uuid )), \ E_USER_WARNING );
317
317
318
318
return null ;
319
319
}
@@ -332,7 +332,7 @@ public static function uuid_parse($uuid)
332
332
public static function uuid_unparse ($ bytes )
333
333
{
334
334
if (!\is_string ($ bytes = self ::toString ($ bytes ))) {
335
- trigger_error (sprintf ('uuid_unparse() expects parameter 1 to be string, %s given ' , \gettype ($ bytes )), E_USER_WARNING );
335
+ trigger_error (sprintf ('uuid_unparse() expects parameter 1 to be string, %s given ' , \gettype ($ bytes )), \ E_USER_WARNING );
336
336
337
337
return null ;
338
338
}
@@ -384,9 +384,9 @@ private static function uuid_generate_time()
384
384
$ time = substr ($ time , 11 ).substr ($ time , 2 , 7 );
385
385
386
386
if (\PHP_INT_SIZE >= 8 ) {
387
- $ time = str_pad (dechex ($ time + self ::TIME_OFFSET_INT ), 16 , '0 ' , STR_PAD_LEFT );
387
+ $ time = str_pad (dechex ($ time + self ::TIME_OFFSET_INT ), 16 , '0 ' , \ STR_PAD_LEFT );
388
388
} else {
389
- $ time = str_pad (self ::toBinary ($ time ), 8 , "\0" , STR_PAD_LEFT );
389
+ $ time = str_pad (self ::toBinary ($ time ), 8 , "\0" , \ STR_PAD_LEFT );
390
390
$ time = self ::binaryAdd ($ time , self ::TIME_OFFSET_BIN );
391
391
$ time = bin2hex ($ time );
392
392
}
@@ -448,12 +448,12 @@ private static function parse($uuid)
448
448
return null ;
449
449
}
450
450
451
- return array (
451
+ return [
452
452
'time ' => '0 ' .$ matches ['time_hi ' ].$ matches ['time_mid ' ].$ matches ['time_low ' ],
453
453
'version ' => hexdec ($ matches ['version ' ]),
454
454
'clock_seq ' => hexdec ($ matches ['clock_seq ' ]),
455
455
'node ' => $ matches ['node ' ],
456
- ) ;
456
+ ] ;
457
457
}
458
458
459
459
private static function toString ($ v )
@@ -471,7 +471,7 @@ private static function toBinary($digits)
471
471
$ count = \strlen ($ digits );
472
472
473
473
while ($ count ) {
474
- $ quotient = array () ;
474
+ $ quotient = [] ;
475
475
$ remainder = 0 ;
476
476
477
477
for ($ i = 0 ; $ i !== $ count ; ++$ i ) {
@@ -497,7 +497,7 @@ private static function toDecimal($bytes)
497
497
$ bytes = array_values (unpack ('C* ' , $ bytes ));
498
498
499
499
while ($ count = \count ($ bytes )) {
500
- $ quotient = array () ;
500
+ $ quotient = [] ;
501
501
$ remainder = 0 ;
502
502
503
503
for ($ i = 0 ; $ i !== $ count ; ++$ i ) {
0 commit comments