Repository
class Repository implements ReplicableContext
Traits
Constants
| CONTEXT_KEY |
|
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected array<string, mixed> | $data | The contextual data that flows to logs and jobs. |
|
| $hidden | The hidden contextual data that flows to jobs but not logs. |
||
| static protected null|Throwable, string, string, bool): mixed | $handleUnserializeExceptionsUsing | The callback that should handle unserialize exceptions. |
Methods
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Get the property value prepared for serialization.
Get the restored property value after deserialization.
Get the query for model restoration.
Get the context repository instance for the current coroutine.
Determine if a context repository instance exists for the current coroutine.
Determine if the given key exists.
Determine if the given key is missing.
Retrieve all the context data.
Retrieve the given key's value.
Retrieve the given key's value and then forget it.
Retrieve only the values of the given keys.
Retrieve all values except those with the given keys.
Add a context value.
Add a context value if it does not exist yet.
Add a context value if it does not exist yet, and return the value.
Forget the given context key.
Push values onto a context stack.
Pop the latest value from a context stack.
Determine if the given value is in the given stack.
Increment a context counter.
Decrement a context counter.
Determine if the given key exists within the hidden context data.
Determine if the given key is missing within the hidden context data.
Retrieve all the hidden context data.
Retrieve the given key's hidden value.
Retrieve the given key's hidden value and then forget it.
Retrieve only the hidden values of the given keys.
Retrieve all hidden values except those with the given keys.
Add a hidden context value.
Add a hidden context value if it does not exist yet.
Add a hidden context value if it does not exist yet, and return the value.
Forget the given hidden context key.
Push values onto a hidden context stack.
Pop the latest value from a hidden context stack.
Determine if the given value is in the given hidden stack.
Run a callback with temporary context, then restore.
Determine if the context is empty.
Flush all context data.
Create an independent copy with the same data and hidden values.
Register a callback to execute before context is dehydrated.
Register a callback to execute after context has been hydrated.
Set the callback to handle unserialize exceptions.
Flush all static state.
Dehydrate the context into a serializable payload.
Hydrate the context from a serialized payload.
Determine if a given key can be used as a stack.
Determine if a given key can be used as a hidden stack.
Details
in
Conditionable at line 23
mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
in
Conditionable at line 56
mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
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.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
SerializesAndRestoresModelIdentifiers at line 21
protected mixed
getSerializedPropertyValue(mixed $value, bool $withRelations = true)
Get the property value prepared for serialization.
in
SerializesAndRestoresModelIdentifiers at line 64
protected mixed
getRestoredPropertyValue(mixed $value)
Get the restored property value after deserialization.
in
SerializesAndRestoresModelIdentifiers at line 78
protected Collection
restoreCollection(ModelIdentifier $value)
Restore a queueable collection instance.
in
SerializesAndRestoresModelIdentifiers at line 118
Model
restoreModel(ModelIdentifier $value)
Restore the model from the model identifier instance.
in
SerializesAndRestoresModelIdentifiers at line 137
protected Builder
getQueryForModelRestoration(Model $model, array|int|string $ids)
Get the query for model restoration.
at line 56
__construct(Dispatcher $events)
Create a new context repository instance.
at line 68
static Repository
getInstance()
Get the context repository instance for the current coroutine.
Creates the instance on first access. For hot paths that should avoid unnecessary allocation (log processors, queue hooks), use hasInstance() to check first.
at line 81
static bool
hasInstance()
Determine if a context repository instance exists for the current coroutine.
Unlike getInstance(), this does NOT create one if it doesn't exist.
at line 91
bool
has(string $key)
Determine if the given key exists.
at line 99
bool
missing(string $key)
Determine if the given key is missing.
at line 109
array
all()
Retrieve all the context data.
at line 117
mixed
get(string $key, mixed $default = null)
Retrieve the given key's value.
at line 125
mixed
pull(string $key, mixed $default = null)
Retrieve the given key's value and then forget it.
at line 138
array
only(array $keys)
Retrieve only the values of the given keys.
at line 149
array
except(array $keys)
Retrieve all values except those with the given keys.
at line 160
Repository
add(string|array $key, mixed $value = null)
Add a context value.
at line 176
Repository
addIf(string $key, mixed $value)
Add a context value if it does not exist yet.
at line 188
mixed
remember(string $key, mixed $value)
Add a context value if it does not exist yet, and return the value.
at line 205
Repository
forget(string|array $key)
Forget the given context key.
at line 220
Repository
push(string $key, mixed ...$values)
Push values onto a context stack.
at line 239
mixed
pop(string $key)
Pop the latest value from a context stack.
at line 253
bool
stackContains(string $key, mixed $value, bool $strict = false)
Determine if the given value is in the given stack.
at line 275
Repository
increment(string $key, int $amount = 1)
Increment a context counter.
at line 290
Repository
decrement(string $key, int $amount = 1)
Decrement a context counter.
at line 300
bool
hasHidden(string $key)
Determine if the given key exists within the hidden context data.
at line 308
bool
missingHidden(string $key)
Determine if the given key is missing within the hidden context data.
at line 318
array
allHidden()
Retrieve all the hidden context data.
at line 326
mixed
getHidden(string $key, mixed $default = null)
Retrieve the given key's hidden value.
at line 334
mixed
pullHidden(string $key, mixed $default = null)
Retrieve the given key's hidden value and then forget it.
at line 347
array
onlyHidden(array $keys)
Retrieve only the hidden values of the given keys.
at line 358
array
exceptHidden(array $keys)
Retrieve all hidden values except those with the given keys.
at line 369
Repository
addHidden(string|array $key, mixed $value = null)
Add a hidden context value.
at line 385
Repository
addHiddenIf(string $key, mixed $value)
Add a hidden context value if it does not exist yet.
at line 397
mixed
rememberHidden(string $key, mixed $value)
Add a hidden context value if it does not exist yet, and return the value.
at line 414
Repository
forgetHidden(string|array $key)
Forget the given hidden context key.
at line 429
Repository
pushHidden(string $key, mixed ...$values)
Push values onto a hidden context stack.
at line 448
mixed
popHidden(string $key)
Pop the latest value from a hidden context stack.
at line 462
bool
hiddenStackContains(string $key, mixed $value, bool $strict = false)
Determine if the given value is in the given hidden stack.
at line 491
mixed
scope(callable $callback, array $data = [], array $hidden = [])
Run a callback with temporary context, then restore.
at line 517
bool
isEmpty()
Determine if the context is empty.
at line 527
Repository
flush()
Flush all context data.
at line 542
ReplicableContext
replicate()
Create an independent copy with the same data and hidden values.
Used by coroutine context copying via ReplicableContext to ensure forked coroutines get their own instance rather than sharing an object reference with the parent.
at line 560
Repository
dehydrating(callable $callback)
Register a callback to execute before context is dehydrated.
When the dispatcher is the application's worker-shared dispatcher, per-request registration persists and affects subsequent requests.
at line 576
Repository
hydrated(callable $callback)
Register a callback to execute after context has been hydrated.
When the dispatcher is the application's worker-shared dispatcher, per-request registration persists and affects subsequent requests.
at line 591
Repository
handleUnserializeExceptionsUsing(callable|null $callback)
Set the callback to handle unserialize exceptions.
The callback persists in a static property for the worker lifetime and handles every subsequent context hydration failure.
at line 604
static void
flushState()
Flush all static state.
at line 624
array|null
dehydrate()
| internal |
Dehydrate the context into a serializable payload.
Creates a clone of this instance, dispatches ContextDehydrating so listeners can modify the clone (not the original), then serializes all values. Uses SerializesAndRestoresModelIdentifiers to handle Eloquent models.
Returns null if both data and hidden are empty after dehydration hooks run.
at line 656
Repository
hydrate(array|null $context)
| internal |
Hydrate the context from a serialized payload.
Flushes existing data, deserializes the payload, then dispatches ContextHydrated so listeners can react to the restored data. Uses SerializesAndRestoresModelIdentifiers to restore Eloquent models.
at line 705
protected bool
isStackable(string $key)
Determine if a given key can be used as a stack.
at line 714
protected bool
isHiddenStackable(string $key)
Determine if a given key can be used as a hidden stack.