RateLimiter
class RateLimiter extends MultipleInstanceManager mixin Limiter
Traits
Properties
| protected Repository | $config | The configuration repository instance. |
from MultipleInstanceManager |
| protected array | $instances | The array of resolved instances. |
from MultipleInstanceManager |
| protected array | $customCreators | The registered custom instance creators. |
from MultipleInstanceManager |
| protected string | $driverKey | The key name of the "driver" equivalent configuration option. |
from MultipleInstanceManager |
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected Closure> | $limiters | The configured named limiter callbacks. |
|
| protected array<string, string> | $limiterStores | The optional store selected for each named limiter. |
|
| protected list<Closure(string): ?string> | $keyScopeResolvers | The callbacks used to resolve scopes for named limiter keys. |
Methods
Get the default rate limiter store name.
Set the default rate limiter store name.
Get the store-specific configuration.
Attempt to get an instance from the local cache.
Resolve a store and wrap it in the public limiter API.
Unset the given instances.
Disconnect the given instance and remove from local cache.
Dynamically call a macro or the default limiter.
Mix another object into the class.
Dynamically handle calls to the class.
Get the store registered for a named rate limiter.
Resolve the contributed scopes for a named limiter.
Create a worker-lifetime array store.
Create a database store.
Create a Redis store.
Create a Swoole store.
Normalize an enum or string manager name.
Flush all static state.
Details
in
RebindsCallbacksToSelf at line 18
protected Closure|null
bindCallbackToSelf(Closure $callback)
Bind the provided callback to the class instance.
in
MultipleInstanceManager at line 44
__construct(Application $app)
Create a new manager instance.
at line 132
string
getDefaultInstance()
Get the default rate limiter store name.
at line 142
void
setDefaultInstance(string $name)
Set the default rate limiter store name.
Mutates process-global config; per-request use races across coroutines.
at line 151
array
getInstanceConfig(string $name)
Get the store-specific configuration.
in
MultipleInstanceManager at line 72
mixed
instance(string|null $name = null)
Get an instance by name.
in
MultipleInstanceManager at line 84
protected mixed
get(string $name)
Attempt to get an instance from the local cache.
at line 165
protected mixed
resolve(string $name)
Resolve a store and wrap it in the public limiter API.
in
MultipleInstanceManager at line 127
protected mixed
callCustomCreator(array $config)
Call a custom instance creator.
in
MultipleInstanceManager at line 141
MultipleInstanceManager
forgetInstance(array|string|null $name = null)
Unset the given instances.
Mutates the singleton's instance cache; concurrent coroutines may already hold a reference to the forgotten instance and next resolution will rebuild.
in
MultipleInstanceManager at line 162
void
purge(string|null $name = null)
Disconnect the given instance and remove from local cache.
Mutates the singleton's instance cache; concurrent coroutines may already hold a reference to the instance and next resolution will rebuild.
in
MultipleInstanceManager at line 181
MultipleInstanceManager
extend(string $name, Closure $callback)
Register a custom instance creator Closure.
Anonymous closures run in this manager's class scope; non-static closures also receive the manager as $this.
The callback persists in the singleton's customCreators array for the worker lifetime and applies to every subsequent instance resolution.
in
MultipleInstanceManager at line 205
MultipleInstanceManager
setApplication(Application $app)
Set the application instance used by the manager.
Swaps the singleton's application and configuration references without rebuilding resolved instances; per-request use races across coroutines and breaks every concurrent resolution through this manager.
at line 300
mixed
__call(string $method, array $parameters)
Dynamically call a macro or the default limiter.
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 54
Limiter
store(UnitEnum|string|null $name = null)
Get a limiter store by name.
at line 72
RateLimiter
for(UnitEnum|string $name, Closure $callback, UnitEnum|string|null $store = null)
Register a named rate limiter configuration.
On the shared manager, the callback and store selection persist for the worker lifetime and affect every subsequent request.
at line 94
Closure|null
limiter(UnitEnum|string $name)
Get the given named rate limiter.
at line 102
string|null
limiterStore(UnitEnum|string $name)
Get the store registered for a named rate limiter.
at line 117
void
resolveKeyScopeUsing(Closure|null $resolver)
Register a named limiter key scope resolver.
Each non-null callback is appended in registration order, while passing null clears every registered callback. On the shared manager, the callbacks persist for the worker lifetime and affect every subsequent named limiter operation.
at line 191
protected array
resolveKeyScopes(string $limiterName)
Resolve the contributed scopes for a named limiter.
at line 209
protected Store
createWorkerArrayDriver()
Create a worker-lifetime array store.
at line 217
protected Store
createDatabaseDriver(array $config)
Create a database store.
at line 240
protected Store
createRedisDriver(array $config)
Create a Redis store.
at line 257
protected Store
createSwooleDriver(array $config)
Create a Swoole store.
at line 282
protected string
normalizeName(UnitEnum|string $name)
Normalize an enum or string manager name.
at line 292
static void
flushState()
Flush all static state.