DbAssignmentStore
Rasuvaeff\Yii3AbTestingDb\DbAssignmentStore
Class · rasuvaeff/yii3-ab-testing-db · Source · implements ConfigurationAwareAssignmentStore, AssignmentStore
Server-side sticky assignments: one row per (experiment, subject).
The cookie store in yii3-ab-testing-web is browser-scoped — it loses the assignment when the visitor clears cookies or switches device, and it ignores the subject id entirely because the cookie is the subject. This one is keyed by the subject, so an authenticated user keeps their variant everywhere.
subject_id is a persistent identifier and therefore personal data when it is a user id. Use forget() to satisfy an erasure request, and deleteExperiment() to drop the rows of an experiment that has ended; neither happens automatically, because deleting analytics-relevant history is the operator's decision, not the library's.
Constructor
new DbAssignmentStore(
Yiisoft\Db\Connection\ConnectionInterface $db,
string $table = 'ab_assignments',
Psr\Clock\ClockInterface $clock = new SystemClock(),
)Methods
get()
get(string $experiment, string $subjectId): ?stringput()
put(
string $experiment,
string $subjectId,
string $variant,
): voidgetForConfiguration()
getForConfiguration(
string $experiment,
string $subjectId,
?string $configurationId,
): ?stringReturns the stored variant only when it was drawn from the same configuration. A reweight changes the identity, and the old variant then belongs to bucket boundaries that no longer exist.
putForConfiguration()
putForConfiguration(
string $experiment,
string $subjectId,
string $variant,
?string $configurationId,
): voidforget()
forget(string $subjectId): intErases every assignment of a subject, across all experiments.
deleteExperiment()
deleteExperiment(string $experiment): intDrops the assignments of one experiment, for cleanup after it ends.