Decorator
class Decorator implements CanListStoredFeatures, CanSetManyFeaturesForScopes, Driver, HasFlushableCache mixin PendingScopedFeatureInteraction
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected string | $name | The driver name. |
|
| protected Driver | $driver | The driver being decorated. |
|
| protected Closure(): mixed | $defaultScopeResolver | The default scope resolver. |
|
| protected null|FeaturePartition | $partitionResolver | The resolver of the store's current partition. |
|
| protected Container | $container | The container instance. |
|
| protected array<string, mixed> | $nameMap | Map of feature names to their implementations. |
|
| protected array<class-string, string> | $classNames | The feature names of feature classes. |
|
| protected array<string, class-string> | $featureClasses | The implementation classes of features defined from feature classes. |
|
| protected ReflectionFunctionAbstract> | $resolverFunctions | The reflected resolvers of defined features. |
|
| protected array<string, bool> | $beforeHookAcceptsNull | Whether the before hooks of defined features accept a null scope. |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically create a pending feature interaction.
Create a new driver decorator instance.
Discover and register the application's feature classes.
Define an initial feature flag state resolver.
Resolve the feature value.
Determine if the resolver can handle the scope.
Reflect the function that resolves a feature.
Determine if the function's scope parameter accepts the scope.
Determine if the type can handle the scope.
Determine if the resolver accepts null scope.
Retrieve the names of all defined features.
Retrieve the names of all stored features.
Get multiple feature flag values.
Get multiple feature flag values that are missing.
Resolve the values of the given features through their before hooks or the driver, and memoize them.
Normalize the features to load.
Retrieve a feature flag's value.
Resolve the before hook value.
Set a feature flag's value.
Set multiple feature flag values.
Create a pending feature interaction for the global scope, ignoring the default scope resolver.
Activate the feature for everyone.
Deactivate the feature for everyone.
Set a feature flag's value for all scopes.
Delete a feature flag's value.
Purge the given feature from storage.
Retrieve the feature's name.
Retrieve the map of feature names to their implementations.
Retrieve the feature's class.
Retrieve the defined features for the given scope.
Resolve the feature name and ensure it is defined.
Determine if the feature should be dynamically defined.
Dynamically define the feature.
Determine if the given feature has a before hook.
Retrieve the implementation feature class for the given feature name.
Resolve the name for a feature class.
Resolve the scope.
Determine if a feature's value is in the cache for the given scope.
Put the given feature's value into the cache.
Remove the given feature's value from the cache.
Forget the values memoized for the connection if its current transaction rolls back.
Get the name of the connection the driver currently uses, or an empty string for drivers without one.
Get the key of the store's current partition.
Retrieve the default scope.
Flush the in-memory cache of feature values.
Invalidate shared cached database values for the current partition.
Details
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
at line 1076
mixed
__call(string $name, array $parameters)
Dynamically create a pending feature interaction.
at line 142
__construct(string $name, Driver $driver, Closure $defaultScopeResolver, Closure|null $partitionResolver, Container $container)
Create a new driver decorator instance.
Feature values are memoized in the current coroutine's PennantState instead of on the decorator, which every request in the worker shares.
at line 157
void
discover(string $namespace = 'App\Features', string|null $path = null)
Discover and register the application's feature classes.
On a shared store, the definitions persist for the worker lifetime and add every discovered class to all() for subsequent requests.
at line 179
void
define(string $feature, callable $resolver = null)
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 231
protected mixed
resolve(string $feature, callable $resolver, mixed $scope)
Resolve the feature value.
at line 249
bool
isResolverValidForScope(callable|string $resolver, mixed $scope)
Determine if the resolver can handle the scope.
at line 259
protected ReflectionFunctionAbstract
resolverFunction(callable|string $resolver)
Reflect the function that resolves a feature.
at line 275
protected bool
functionAcceptsScope(ReflectionFunctionAbstract $function, mixed $scope)
Determine if the function's scope parameter accepts the scope.
at line 295
protected bool
typeAllowsScope(ReflectionType $type, mixed $scope, ReflectionFunctionAbstract $function)
Determine if the type can handle the scope.
at line 361
protected bool
canHandleNullScope(callable|ReflectionFunctionAbstract $resolver)
Determine if the resolver accepts null scope.
at line 377
array
defined()
Retrieve the names of all defined features.
at line 387
array
stored()
Retrieve the names of all stored features.
at line 404
array
getAll(array $features)
| internal |
Get multiple feature flag values.
at line 423
array
getAllMissing(array|string $features)
| internal |
Get multiple feature flag values that are missing.
at line 455
protected array
resolveFeatures(array $features, PennantState $state, string $connection, string $partition)
Resolve the values of the given features through their before hooks or the driver, and memoize them.
at line 507
protected array
normalizeFeaturesToLoad(array|string $features)
Normalize the features to load.
at line 534
mixed
get(string $feature, mixed $scope)
| internal |
Retrieve a feature flag's value.
at line 569
protected mixed
resolveBeforeHook(string $feature, mixed $scope, callable $hook)
Resolve the before hook value.
at line 587
void
set(string $feature, mixed $scope, mixed $value)
| internal |
Set a feature flag's value.
at line 618
void
setAll(array $features)
| internal |
Set multiple feature flag values.
at line 669
PendingScopedFeatureInteraction
globally()
Create a pending feature interaction for the global scope, ignoring the default scope resolver.
at line 679
void
activateForEveryone(UnitEnum|string|array $feature, mixed $value = true)
Activate the feature for everyone.
at line 690
void
deactivateForEveryone(UnitEnum|string|array $feature)
Deactivate the feature for everyone.
at line 701
void
setForAllScopes(string $feature, mixed $value)
| internal |
Set a feature flag's value for all scopes.
at line 719
void
delete(string $feature, mixed $scope)
| internal |
Delete a feature flag's value.
at line 739
void
purge(array|null $features = null)
Purge the given feature from storage.
at line 771
string
name(UnitEnum|string $feature)
Retrieve the feature's name.
at line 781
array
nameMap()
Retrieve the map of feature names to their implementations.
at line 789
mixed
instance(UnitEnum|string $name)
Retrieve the feature's class.
at line 817
Collection
definedFeaturesForScope(mixed $scope)
| internal |
Retrieve the defined features for the given scope.
at line 850
protected string
resolveFeature(UnitEnum|string $feature)
Resolve the feature name and ensure it is defined.
at line 870
protected bool
shouldDynamicallyDefine(string $feature)
Determine if the feature should be dynamically defined.
at line 882
protected string
ensureDynamicFeatureIsDefined(string $feature)
Dynamically define the feature.
at line 898
protected bool
hasBeforeHook(string $feature)
Determine if the given feature has a before hook.
at line 910
protected string|null
implementationClass(string $feature)
Retrieve the implementation feature class for the given feature name.
at line 918
protected string
resolveFeatureName(string $class, object $instance)
Resolve the name for a feature class.
at line 932
protected mixed
resolveScope(mixed $scope)
Resolve the scope.
at line 942
protected bool
isCached(PennantState $state, string $connection, string $partition, string $feature, string $scope)
Determine if a feature's value is in the cache for the given scope.
at line 950
protected void
putInCache(PennantState $state, string $connection, string $partition, string $feature, string $scope, mixed $value)
Put the given feature's value into the cache.
at line 958
protected void
removeFromCache(PennantState $state, string $connection, string $partition, string $feature, string $scope)
Remove the given feature's value from the cache.
at line 968
protected void
trackTransaction(PennantState $state, string $connection)
Forget the values memoized for the connection if its current transaction rolls back.
Values read or written inside a transaction may never be committed.
at line 995
protected string
connectionName()
Get the name of the connection the driver currently uses, or an empty string for drivers without one.
at line 1003
protected string
partitionKey()
Get the key of the store's current partition.
at line 1011
protected mixed
defaultScope()
Retrieve the default scope.
at line 1021
void
flushCache()
Flush the in-memory cache of feature values.
Only the current coroutine's values are flushed.
at line 1037
void
flushSharedCache()
Invalidate shared cached database values for the current partition.
at line 1047
Driver
getDriver()
Get the underlying feature driver.