Skip to content

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 ​

php
new DbAssignmentStore(
    Yiisoft\Db\Connection\ConnectionInterface $db,
    string $table = 'ab_assignments',
    Psr\Clock\ClockInterface $clock = new SystemClock(),
)

Methods ​

get() ​

php
get(string $experiment, string $subjectId): ?string

put() ​

php
put(
    string $experiment,
    string $subjectId,
    string $variant,
): void

getForConfiguration() ​

php
getForConfiguration(
    string $experiment,
    string $subjectId,
    ?string $configurationId,
): ?string

Returns 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() ​

php
putForConfiguration(
    string $experiment,
    string $subjectId,
    string $variant,
    ?string $configurationId,
): void

forget() ​

php
forget(string $subjectId): int

Erases every assignment of a subject, across all experiments.

deleteExperiment() ​

php
deleteExperiment(string $experiment): int

Drops the assignments of one experiment, for cleanup after it ends.