CoroutineContext
class CoroutineContext
Properties
| static protected TValue> | $nonCoroutineContext |
Methods
Store a value in the current context.
Retrieve a value from the current context.
Determine if a value exists in the current context.
Remove a value from the current context.
Copy context from another coroutine into the current coroutine.
Capture context values as an array.
Retrieve the value and store it if not exists.
Set multiple key-value pairs in the context.
Copy context data from non-coroutine context to the specified coroutine context.
Copy context data from the specified coroutine context to non-coroutine context.
Get a value from non-coroutine context only.
Clear specific keys from non-coroutine context only.
Flush all context data for the specified coroutine.
Get the raw context storage for the current or specified coroutine.
Details
at line 33
static mixed
set(UnitEnum|string $id, mixed $value, int|null $coroutineId = null)
Store a value in the current context.
at line 55
static mixed
get(UnitEnum|string $id, mixed $default = null, int|null $coroutineId = null)
Retrieve a value from the current context.
at line 74
static bool
has(UnitEnum|string $id, int|null $coroutineId = null)
Determine if a value exists in the current context.
at line 91
static void
forget(UnitEnum|string $id, int|null $coroutineId = null)
Remove a value from the current context.
at line 109
static void
copyFrom(int $fromCoroutineId, array $keys = [])
Copy context from another coroutine into the current coroutine.
Merges into the current coroutine's context — existing values that are not in the source are preserved. Matching keys are overwritten.
at line 124
static array
captureFrom(array $keys = [], int|null $fromCoroutineId = null)
Capture context values as an array.
Replicable values are copied in the calling coroutine at capture time.
at line 151
static mixed
override(UnitEnum|string $id, Closure $closure, int|null $coroutineId = null)
Retrieve a value and replace it with the result of a closure.
at line 173
static mixed
getOrSet(UnitEnum|string $id, mixed $value, int|null $coroutineId = null)
Retrieve the value and store it if not exists.
at line 185
static void
setMany(array $values, int|null $coroutineId = null)
Set multiple key-value pairs in the context.
at line 216
static void
copyFromNonCoroutine(array $keys = [], int|null $coroutineId = null)
Copy context data from non-coroutine context to the specified coroutine context.
Merges into the target coroutine's context — existing values that are not in the source are preserved. Matching keys are overwritten.
at line 242
static void
copyToNonCoroutine(array $keys = [], int|null $coroutineId = null)
Copy context data from the specified coroutine context to non-coroutine context.
Tests only. This copies coroutine-local values into worker-global storage, so request-time use can leak or race across concurrent requests.
at line 271
static mixed
getFromNonCoroutine(UnitEnum|string $id, mixed $default = null)
Get a value from non-coroutine context only.
Unlike get() which reads from coroutine context when inside a coroutine, this always reads from non-coroutine storage regardless of current context.
at line 284
static void
clearFromNonCoroutine(array $keys)
Clear specific keys from non-coroutine context only.
Tests only. This mutates worker-global storage, so request-time use can race with concurrent requests using the same keys.
at line 294
static void
flush(int|null $coroutineId = null)
Flush all context data for the specified coroutine.
at line 310
static array|ArrayObject|null
getContainer(int|null $coroutineId = null)
Get the raw context storage for the current or specified coroutine.