DatabaseDriver
class DatabaseDriver implements CanListStoredFeatures, CanSetManyFeaturesForScopes, Driver, UsesDatabaseConnection
Constants
| CREATED_AT |
The name of the "created at" column. |
| UPDATED_AT |
The name of the "updated at" column. |
| QUERY_GROUP_LIMIT |
The maximum number of feature groups in one read query. Half of SQLite's default expression depth limit of 1000. |
| QUERY_BINDING_LIMIT |
The maximum number of bindings in one read query. |
| WRITE_ROW_LIMIT |
The maximum number of rows in one write statement. |
Properties
| protected DatabaseManager | $db | The database manager. |
|
| protected string|null | $connection | The store's connection name, or null for the default connection. |
|
| protected string | $table | The store's table. |
|
| protected null|FeaturePartition | $partitionResolver | The resolver of the store's current partition. |
|
| protected StoredValueCache|null | $cache | The shared cache of stored values. |
|
| protected null|FeaturePartition): void | $writeGuard | The callback that guards database writes. |
|
| protected array<string, callable(mixed): mixed> | $featureStateResolvers | The feature state resolvers. |
|
| protected stdClass | $unknownFeatureValue | The sentinel value for unknown features. |
Methods
Create a new driver instance.
Define an initial feature flag state resolver.
Retrieve the names of all defined features.
Retrieve the names of all stored features.
Get multiple feature flag values.
Retrieve a feature flag's value.
Retrieve the values of the given features and scopes, storing initial values for any that are missing.
Read the stored JSON values of the given features and scopes.
Determine the initial value for a given feature and scope.
Set a feature flag's value.
Set multiple feature flag values.
Set a feature flag's value for all scopes.
Insert initial values for the given features and scopes, returning the values that are stored.
Insert the candidate rows, skipping those that already exist, and determine whether every candidate was inserted.
Get a row for the given feature value.
Delete a feature flag's value.
Purge the given feature from storage.
Invalidate the current partition's shared cached values after the transaction commits.
Rotate the shared cache tokens of the given scopes, or of the whole partition, once the write commits.
Get the name of the store's current connection.
Get the store's current partition.
Create a new table query limited to the given partition.
The database connection.
Details
at line 111
__construct(DatabaseManager $db, string|null $connection, string $table, Closure|null $partitionResolver, StoredValueCache|null $cache, array $featureStateResolvers, Closure|null $writeGuard = null)
Create a new driver instance.
at line 139
void
define(string $feature, callable $resolver)
Define an initial feature flag state resolver.
On a shared store, the definition persists for the worker lifetime and applies to every subsequent request.
at line 150
array
defined()
Retrieve the names of all defined features.
at line 161
array
stored()
Retrieve the names of all stored features.
at line 177
array
getAll(array $features)
Get multiple feature flag values.
at line 208
mixed
get(string $feature, mixed $scope)
Retrieve a feature flag's value.
at line 219
protected array
retrieveValues(array $pairs)
Retrieve the values of the given features and scopes, storing initial values for any that are missing.
at line 291
protected array
readStoredValues(array $pairs, FeaturePartition|null $partition, bool $useWritePdo = false, bool $lock = false)
Read the stored JSON values of the given features and scopes.
Features that share the same scopes are combined into one predicate, and the predicates are packed into as few statements as the group and binding limits allow.
at line 374
protected mixed
resolveValue(string $feature, mixed $scope)
Determine the initial value for a given feature and scope.
at line 390
void
set(string $feature, mixed $scope, mixed $value)
Set a feature flag's value.
at line 411
void
setAll(array $features)
Set multiple feature flag values.
at line 455
void
setForAllScopes(string $feature, mixed $value)
Set a feature flag's value for all scopes.
at line 483
protected array
insertMany(FeaturePartition|null $partition, array $pairs)
Insert initial values for the given features and scopes, returning the values that are stored.
When every candidate is known to be inserted, the resolved values are returned as they are. Otherwise the rows are read back and their stored values returned, since a matching row may belong to a concurrent insert. Rows that vanish before they can be read back, such as through a concurrent purge, are resolved and inserted again, at most twice.
at line 568
protected bool
insertCandidates(FeaturePartition|null $partition, array $rows)
Insert the candidate rows, skipping those that already exist, and determine whether every candidate was inserted.
at line 599
protected array
row(FeaturePartition|null $partition, string $feature, string $scope, string $value, CarbonImmutable $now)
Get a row for the given feature value.
at line 621
protected array
uniqueBy(FeaturePartition|null $partition)
Get the columns that identify a stored value.
at line 629
void
delete(string $feature, mixed $scope)
Delete a feature flag's value.
at line 646
void
purge(array|null $features)
Purge the given feature from storage.
at line 670
void
flushSharedCache()
Invalidate the current partition's shared cached values after the transaction commits.
at line 680
protected void
invalidate(FeaturePartition|null $partition, array|null $scopes = null)
Rotate the shared cache tokens of the given scopes, or of the whole partition, once the write commits.
at line 698
string
connectionName()
Get the name of the store's current connection.
at line 713
protected FeaturePartition|null
partition()
Get the store's current partition.
at line 721
protected Builder
newQuery()
Create a new table query.
at line 729
protected Builder
newPartitionQuery(FeaturePartition|null $partition)
Create a new table query limited to the given partition.
at line 743
protected Connection
connection()
The database connection.