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 for a job.
Register a callback to execute after context has been hydrated from a job.
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 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.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
SerializesAndRestoresModelIdentifiers at line 20
protected mixed
getSerializedPropertyValue(mixed $value, bool $withRelations = true)
Get the property value prepared for serialization.
in
SerializesAndRestoresModelIdentifiers at line 54
protected mixed
getRestoredPropertyValue(mixed $value)
Get the restored property value after deserialization.
in
SerializesAndRestoresModelIdentifiers at line 68
protected Collection
restoreCollection(ModelIdentifier $value)
Restore a queueable collection instance.
in
SerializesAndRestoresModelIdentifiers at line 109
Model
restoreModel(ModelIdentifier $value)
Restore the model from the model identifier instance.
in
SerializesAndRestoresModelIdentifiers at line 123
protected Builder
getQueryForModelRestoration(Model $model, array|int|string $ids)
Get the query for model restoration.
at line 55
__construct(Dispatcher $events)
Create a new context repository instance.
at line 67
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 80
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 90
bool
has(string $key)
Determine if the given key exists.
at line 98
bool
missing(string $key)
Determine if the given key is missing.
at line 108
array
all()
Retrieve all the context data.
at line 116
mixed
get(string $key, mixed $default = null)
Retrieve the given key's value.
at line 124
mixed
pull(string $key, mixed $default = null)
Retrieve the given key's value and then forget it.
at line 137
array
only(array $keys)
Retrieve only the values of the given keys.
at line 148
array
except(array $keys)
Retrieve all values except those with the given keys.
at line 159
Repository
add(string|array $key, mixed $value = null)
Add a context value.
at line 174
Repository
addIf(string $key, mixed $value)
Add a context value if it does not exist yet.
at line 186
mixed
remember(string $key, mixed $value)
Add a context value if it does not exist yet, and return the value.
at line 203
Repository
forget(string|array $key)
Forget the given context key.
at line 218
Repository
push(string $key, mixed ...$values)
Push values onto a context stack.
at line 237
mixed
pop(string $key)
Pop the latest value from a context stack.
at line 251
bool
stackContains(string $key, mixed $value, bool $strict = false)
Determine if the given value is in the given stack.
at line 273
Repository
increment(string $key, int $amount = 1)
Increment a context counter.
at line 288
Repository
decrement(string $key, int $amount = 1)
Decrement a context counter.
at line 298
bool
hasHidden(string $key)
Determine if the given key exists within the hidden context data.
at line 306
bool
missingHidden(string $key)
Determine if the given key is missing within the hidden context data.
at line 316
array
allHidden()
Retrieve all the hidden context data.
at line 324
mixed
getHidden(string $key, mixed $default = null)
Retrieve the given key's hidden value.
at line 332
mixed
pullHidden(string $key, mixed $default = null)
Retrieve the given key's hidden value and then forget it.
at line 345
array
onlyHidden(array $keys)
Retrieve only the hidden values of the given keys.
at line 356
array
exceptHidden(array $keys)
Retrieve all hidden values except those with the given keys.
at line 367
Repository
addHidden(string|array $key, mixed $value = null)
Add a hidden context value.
at line 382
Repository
addHiddenIf(string $key, mixed $value)
Add a hidden context value if it does not exist yet.
at line 394
mixed
rememberHidden(string $key, mixed $value)
Add a hidden context value if it does not exist yet, and return the value.
at line 411
Repository
forgetHidden(string|array $key)
Forget the given hidden context key.
at line 426
Repository
pushHidden(string $key, mixed ...$values)
Push values onto a hidden context stack.
at line 445
mixed
popHidden(string $key)
Pop the latest value from a hidden context stack.
at line 459
bool
hiddenStackContains(string $key, mixed $value, bool $strict = false)
Determine if the given value is in the given hidden stack.
at line 488
mixed
scope(callable $callback, array $data = [], array $hidden = [])
Run a callback with temporary context, then restore.
at line 514
bool
isEmpty()
Determine if the context is empty.
at line 524
Repository
flush()
Flush all context data.
at line 539
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 557
Repository
dehydrating(callable $callback)
Register a callback to execute before context is dehydrated for a job.
Boot-only. Registers a listener on the worker-global event dispatcher; per-request registration persists and affects subsequent requests.
at line 573
Repository
hydrated(callable $callback)
Register a callback to execute after context has been hydrated from a job.
Boot-only. Registers a listener on the worker-global event dispatcher; per-request registration persists and affects subsequent requests.
at line 588
Repository
handleUnserializeExceptionsUsing(callable|null $callback)
Set the callback to handle unserialize exceptions.
Boot-only. The callback persists in a static property for the worker lifetime and handles every subsequent context hydration failure.
at line 600
static void
flushState()
Flush all static state.
at line 620
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 652
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 701
protected bool
isStackable(string $key)
Determine if a given key can be used as a stack.
at line 710
protected bool
isHiddenStackable(string $key)
Determine if a given key can be used as a hidden stack.