SubjectIdGeneratorInterface
Rasuvaeff\Yii3AbTestingWeb\SubjectIdGeneratorInterface
Interface · rasuvaeff/yii3-ab-testing-web · Source
Produces the subject id used for A/B assignment — and validates it coming back from the cookie.
Both halves belong to one contract on purpose. The cookie value is attacker-controlled, so SubjectIdMiddleware only reuses a value the generator recognises as its own; a generator that changed the format without changing the check would have every request reject its own cookie, mint a fresh id and — because assignment is deterministic in the subject id — flip the visitor's variant on every page view.
Methods
generate()
generate(): stringisValid()
isValid(string $id): boolWhether a value read from the cookie was produced by this generator. Reject anything tampered, truncated or oversized: a value that passes here becomes the subject id in logs and analytics.