ContextInterface
in
Immutable execution scoped propagation mechanism.
Tags
Table of Contents
Methods
- activate() : ScopeInterface
- Attaches this context as active context.
- createKey() : ContextKeyInterface
- Creates a new context key.
- get() : T|null
- Returns the value assigned to the given key.
- getCurrent() : ContextInterface
- Returns the current context.
- with() : ContextInterface
- Returns a context with the given key set to the given value.
- withContextValue() : ContextInterface
- Returns a context with the given value set.
Methods
activate()
Attaches this context as active context.
public
activate() : ScopeInterface
The returned scope has to be ed. In most
cases this should be done using a try-finally
statement:
$scope = $context->activate();
try {
// ...
} finally {
$scope->detach();
}
Tags
Return values
ScopeInterface —scope to detach the context and restore the previous context
createKey()
Creates a new context key.
public
static createKey(non-empty-string $key) : ContextKeyInterface
Parameters
- $key : non-empty-string
-
name of the key
Tags
Return values
ContextKeyInterface —created key
get()
Returns the value assigned to the given key.
public
get(ContextKeyInterface<string|int, T> $key) : T|null
Parameters
- $key : ContextKeyInterface<string|int, T>
-
key to get
Tags
Return values
T|null —value assigned to $key
, or null if no such value exists
getCurrent()
Returns the current context.
public
static getCurrent() : ContextInterface
Tags
Return values
ContextInterface —current context
with()
Returns a context with the given key set to the given value.
public
with(ContextKeyInterface<string|int, T> $key, T|null $value) : ContextInterface
Parameters
- $key : ContextKeyInterface<string|int, T>
-
key to set
- $value : T|null
-
value to set
Tags
Return values
ContextInterface —a context with the given key set to $value
withContextValue()
Returns a context with the given value set.
public
withContextValue(ImplicitContextKeyedInterface $value) : ContextInterface
Parameters
- $value : ImplicitContextKeyedInterface
-
value to set
Tags
Return values
ContextInterface —a context with the given $value