1 | <?php |
||
20 | class UuidHelper |
||
21 | { |
||
22 | /** |
||
23 | * Generate a UUID string (version 4 by default). |
||
24 | * |
||
25 | * @return string canonical format UUID, i.e. 25769c6c-d34d-4bfe-ba98-e0ee856f3e7a |
||
26 | */ |
||
27 | 2 | public static function uuid() |
|
31 | |||
32 | /** |
||
33 | * Checks if the given string looks like a UUID in the canonical format, |
||
34 | * i.e. 25769c6c-d34d-4bfe-ba98-e0ee856f3e7a. This check is case |
||
35 | * insensitive. |
||
36 | * |
||
37 | * @param string $uuid UUID String to check |
||
38 | * |
||
39 | * @return bool whether or not it matches the pattern. |
||
40 | */ |
||
41 | 1 | public static function isValid($uuid) |
|
47 | |||
48 | /** |
||
49 | * Converts a UUID string into a compact binary string. |
||
50 | * |
||
51 | * @param string $uuid UUID in canonical format, i.e. 25769c6c-d34d-4bfe-ba98-e0ee856f3e7a |
||
52 | * |
||
53 | * @return string compact 16-byte binary representation of the UUID. |
||
54 | */ |
||
55 | 2 | public static function uuid2bin($uuid) |
|
66 | |||
67 | /** |
||
68 | * Converts a compact 16-byte binary representation of the UUID into |
||
69 | * a string in canonical format, i.e. 25769c6c-d34d-4bfe-ba98-e0ee856f3e7a. |
||
70 | * |
||
71 | * @param string $uuidBin compact 16-byte binary representation of the UUID. |
||
72 | * |
||
73 | * @return string UUID in canonical format, i.e. 25769c6c-d34d-4bfe-ba98-e0ee856f3e7a |
||
74 | */ |
||
75 | 2 | public static function bin2uuid($uuidBin) |
|
94 | } |
||
95 |