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.
Store a value in non-coroutine context only.
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 34
static mixed
set(UnitEnum|string $id, mixed $value, int|null $coroutineId = null)
Store a value in the current context.
at line 56
static mixed
get(UnitEnum|string $id, mixed $default = null, int|null $coroutineId = null)
Retrieve a value from the current context.
at line 75
static bool
has(UnitEnum|string $id, int|null $coroutineId = null)
Determine if a value exists in the current context.
at line 92
static void
forget(UnitEnum|string $id, int|null $coroutineId = null)
Remove a value from the current context.
at line 110
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 126
static array
captureFrom(array $keys = [], int|null $fromCoroutineId = null)
Capture context values as an array.
Replicable values are copied and non-copyable values are omitted in the calling coroutine at capture time.
at line 147
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 169
static mixed
getOrSet(UnitEnum|string $id, mixed $value, int|null $coroutineId = null)
Retrieve the value and store it if not exists.
at line 181
static void
setMany(array $values, int|null $coroutineId = null)
Set multiple key-value pairs in the context.
at line 212
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 237
static void
copyToNonCoroutine(array $keys = [], int|null $coroutineId = null)
Copy context data from the specified coroutine context to non-coroutine context.
This copies coroutine-local values into worker-global storage, so request-time use can leak or race across concurrent requests.
at line 285
static mixed
setNonCoroutine(UnitEnum|string $id, mixed $value)
Store a value in non-coroutine context only.
This writes worker-global storage even from a coroutine, so request-time use can leak state between concurrent requests.
at line 301
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 314
static void
clearFromNonCoroutine(array $keys)
Clear specific keys from non-coroutine context only.
This mutates worker-global storage, so request-time use can race with concurrent requests using the same keys.
at line 325
static void
flush(int|null $coroutineId = null)
Flush all context data for the specified coroutine.
at line 341
static array|ArrayObject|null
getContainer(int|null $coroutineId = null)
Get the raw context storage for the current or specified coroutine.