Skip to content

Assignment ​

Rasuvaeff\Yii3AbTesting\Assignment

Class · rasuvaeff/yii3-ab-testing · Source

The outcome of resolving a subject into a variant.

Two independent axes describe it: DecisionReason says why this variant rather than the hash bucket, AssignmentSource says where the value came from. They replace the four overlapping booleans of v1, which could not express a sticky-served forced variant and, worse, could not tell a disabled experiment apart from a targeting miss once serialized.

Constructor ​

php
new Assignment(
    string $experiment,
    string $variant,
    string $subjectId,
    DecisionReason $reason = DecisionReason::Assigned,
    AssignmentSource $source = AssignmentSource::Computed,
    ?AssignmentContext $context = null,
    ?string $configurationId = null,
)

Properties ​

PropertyTypeReadonlyDescription
experimentstringyes
variantstringyes
subjectIdstringyes
reasonDecisionReasonyes
sourceAssignmentSourceyes
context?AssignmentContextyes
configurationId?stringyes

Methods ​

isVariant() ​

php
isVariant(string $variant): bool

isFallback() ​

php
isFallback(): bool

Served the fallback variant, for either of the two reasons.

isForced() ​

php
isForced(): bool

Overridden explicitly, bypassing targeting and any store.

isTargetingMismatch() ​

php
isTargetingMismatch(): bool

Fell back because the targeting rules did not match the context.

isSticky() ​

php
isSticky(): bool

Replayed from an AssignmentStore rather than computed.