final class PrecomputedPresenceVerifier implements DatabasePresenceVerifierInterface

Presence verifier that returns pre-computed results from batched queries.

Used by BatchDatabaseChecker to replace per-item DB queries with lookup-set checks. Original Exists/Unique rule objects stay in place, so the full message resolution pipeline works unchanged.

Results are scoped by table+column. Falls back to the provided verifier for lookups that weren't pre-computed (rules with closure callbacks).

Methods

__construct(PresenceVerifierInterface|null $fallback = null)

No description

void
addLookup(string $table, string $column, array $values)

Register pre-computed values for a table+column pair.

int
getCount(string $collection, string $column, string $value, int|string|null $excludeId = null, string|null $idColumn = null, array $extra = [])

Count the number of objects in a collection having the given value.

int
getMultiCount(string $collection, string $column, array $values, array $extra = [])

Count the number of objects in a collection with the given values.

void
setConnection(string|null $connection)

Set the connection to be used.

bool
hasLookups()

Determine if any lookups have been registered.

Details

at line 22
__construct(PresenceVerifierInterface|null $fallback = null)

No description

Parameters

PresenceVerifierInterface|null $fallback

at line 35
void addLookup(string $table, string $column, array $values)

Register pre-computed values for a table+column pair.

Values are cast to strings and stored as a flip map for O(1) isset() lookups. String cast matches database implicit type coercion behavior.

Parameters

string $table
string $column
array $values

values that exist in the database

Return Value

void

at line 57
int getCount(string $collection, string $column, string $value, int|string|null $excludeId = null, string|null $idColumn = null, array $extra = [])

Count the number of objects in a collection having the given value.

Returns 1 if the value exists in the precomputed lookup, 0 otherwise. Falls back to the original verifier when no lookup was registered for this table:column pair.

Parameters

string $collection
string $column
string $value
int|string|null $excludeId
string|null $idColumn
array $extra

Return Value

int

at line 78
int getMultiCount(string $collection, string $column, array $values, array $extra = [])

Count the number of objects in a collection with the given values.

Uses distinct counting to match DatabasePresenceVerifier's ->distinct()->count($column) semantics. Duplicate input values are counted only once.

Parameters

string $collection
string $column
array $values
array $extra

Return Value

int

at line 111
void setConnection(string|null $connection)

Set the connection to be used.

Delegates to the fallback verifier if it supports connections.

Parameters

string|null $connection

Return Value

void

at line 121
bool hasLookups()

Determine if any lookups have been registered.

Return Value

bool