feat: shortened and filename-safe request ids

This commit is contained in:
Björn Fromme committed 2026-03-16 12:03:00 +01:00
1 parent 1cc7a025a1
commit 33609ab534
6 files changed
+70 -4

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace App\Service;
class RequestIdGenerator
{
private const TIMESTAMP_LENGTH = 10;
private const RANDOM_LENGTH = 8;
public function generateBaseId(): string
{
$timestampMs = (int) floor(microtime(true) * 1000);
$timestampPart = str_pad(base_convert((string) $timestampMs, 10, 36), self::TIMESTAMP_LENGTH, '0', STR_PAD_LEFT);
$maxRandomValue = (36 ** self::RANDOM_LENGTH) - 1;
$randomPart = str_pad(base_convert((string) random_int(0, $maxRandomValue), 10, 36), self::RANDOM_LENGTH, '0', STR_PAD_LEFT);
return sprintf('r-%s-%s', $timestampPart, $randomPart);
}
}