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 41
__construct(Application $app)
Create a new manager instance.
at line 127
string
getDefaultInstance()
Get the default rate limiter store name.
at line 137
void
setDefaultInstance(string $name)
Set the default rate limiter store name.
Boot-only. Mutates process-global config; per-request use races across coroutines.
at line 145
array
getInstanceConfig(string $name)
Get the store-specific configuration.
in
MultipleInstanceManager at line 68
mixed
instance(string|null $name = null)
Get an instance by name.
in
MultipleInstanceManager at line 80
protected mixed
get(string $name)
Attempt to get an instance from the local cache.
at line 159
protected mixed
resolve(string $name)
Resolve a store and wrap it in the public limiter API.
in
MultipleInstanceManager at line 123
protected mixed
callCustomCreator(array $config)
Call a custom instance creator.
in
MultipleInstanceManager at line 137
MultipleInstanceManager
forgetInstance(array|string|null $name = null)
Unset the given instances.
Boot or tests only. 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 157
void
purge(string|null $name = null)
Disconnect the given instance and remove from local cache.
Boot or tests only. 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 176
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.
Boot-only. The callback persists in the singleton's customCreators array for the worker lifetime and applies to every subsequent instance resolution.
in
MultipleInstanceManager at line 199
MultipleInstanceManager
setApplication(Application $app)
Set the application instance used by the manager.
Tests only. 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 294
mixed
__call(string $method, array $parameters)
Dynamically call a macro or the default limiter.
in
Macroable at line 28
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 41
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 68
static void
flushMacros()
Flush the existing macros.
Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
at line 53
Limiter
store(UnitEnum|string|null $name = null)
Get a limiter store by name.
at line 69
RateLimiter
for(UnitEnum|string $name, Closure $callback, UnitEnum|string|null $store = null)
Register a named rate limiter configuration.
Boot-only. The callback and store selection persist on the singleton manager for the worker lifetime and affect every subsequent request.
at line 90
Closure|null
limiter(UnitEnum|string $name)
Get the given named rate limiter.
at line 98
string|null
limiterStore(UnitEnum|string $name)
Get the store registered for a named rate limiter.
at line 113
void
resolveKeyScopeUsing(Closure|null $resolver)
Register a named limiter key scope resolver.
Boot-only. Each non-null callback is appended in registration order, while passing null clears every registered callback. The callbacks persist on the singleton manager for the worker lifetime and affect every subsequent named limiter operation.
at line 185
protected array
resolveKeyScopes(string $limiterName)
Resolve the contributed scopes for a named limiter.
at line 203
protected Store
createWorkerArrayDriver()
Create a worker-lifetime array store.
at line 211
protected Store
createDatabaseDriver(array $config)
Create a database store.
at line 234
protected Store
createRedisDriver(array $config)
Create a Redis store.
at line 251
protected Store
createSwooleDriver(array $config)
Create a Swoole store.
at line 276
protected string
normalizeName(UnitEnum|string $name)
Normalize an enum or string manager name.
at line 286
static void
flushState()
Flush all static state.