RandomnessBackedTokenGenerator
A drop-in replacement for Symfony’s default UriSafeTokenGenerator, generating the same URI-safe base64 shape but through RandomnessInterface instead of a direct random_bytes() call — so a cassette that records the RandomnessInterface reads behind a CSRF token can reproduce that exact token value on replay, and a request whose form POST depends on it does not fail the CSRF check purely because the token could not be regenerated deterministically.
Synopsis
Section titled “Synopsis”final class RandomnessBackedTokenGenerator implements TokenGeneratorInterface
| Implements | TokenGeneratorInterface |
| Source | RandomnessBackedTokenGenerator.php |
Constructor
Section titled “Constructor”__construct()
Section titled “__construct()”public function __construct(RandomnessInterface $randomness = new SystemRandomness(…), int $entropy = 256): mixed
| Parameter | Type | Description |
|---|---|---|
$randomness | RandomnessInterface | |
$entropy | int |
Returns mixed
Methods
Section titled “Methods”| Method | Description |
|---|---|
generateToken(): string | Generates a CSRF token. |
generateToken()
Section titled “generateToken()”public function generateToken(): string
Generates a CSRF token.
Returns string