| 1 | <?php |
||
| 3 | namespace XHGui; |
||
| 4 | |||
| 5 | class Util |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Returns an new ObjectId-like string, where its first 8 |
||
| 9 | * characters encode the current unix timestamp and the |
||
| 10 | * next 16 are random. |
||
| 11 | * |
||
| 12 | * The length will always be 24 bytes. |
||
| 13 | * NOTE: The above assumption will fail as the date value will overflow |
||
| 14 | * past Feb 7 06:28:15 2106 UTC and Jan 19 03:14:07 2038 UTC on 32bit |
||
| 15 | * systems |
||
| 16 | * |
||
| 17 | * @see https://php.net/manual/en/mongodb-bson-objectid.construct.php |
||
| 18 | * |
||
| 19 | * @return string |
||
| 20 | */ |
||
| 21 | public static function generateId(): string |
||
| 22 | { |
||
| 23 | return dechex(time()) . bin2hex(random_bytes(8)); |
||
| 24 | } |
||
| 26 |