|
|
|
|
@ -8,6 +8,7 @@ declare(strict_types = 1); |
|
|
|
|
* @license MIT |
|
|
|
|
*/ |
|
|
|
|
namespace IOcornerstone\Framework\Uuids; |
|
|
|
|
use DateTimeImmutable; |
|
|
|
|
|
|
|
|
|
class UuidV7 |
|
|
|
|
{ |
|
|
|
|
@ -18,8 +19,12 @@ class UuidV7 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function generateUuidV7(): string { |
|
|
|
|
$timestamp = (int)(microtime(true) * 1000); // Real Unix milliseconds |
|
|
|
|
$timeHex = str_pad(dechex((int)$timestamp), 12, '0', STR_PAD_LEFT); |
|
|
|
|
/** |
|
|
|
|
* $milliseconds = (int)(microtime(true) * 1000); // Real Unix milliseconds |
|
|
|
|
*/ |
|
|
|
|
// The completely safe, object-oriented way (no 2038 issue ever) |
|
|
|
|
$milliseconds = (int)((new DateTimeImmutable())->format('U.u') * 1000); |
|
|
|
|
$timeHex = str_pad(dechex($milliseconds), 12, '0', STR_PAD_LEFT); |
|
|
|
|
|
|
|
|
|
$randomHex = bin2hex(random_bytes(10)); |
|
|
|
|
|
|
|
|
|
|