Context
in package
implements
ContextInterface
FinalYes
Tags
Table of Contents
Interfaces
- ContextInterface
- Immutable execution scoped propagation mechanism.
Constants
- OTEL_PHP_DEBUG_SCOPES_DISABLED = 'OTEL_PHP_DEBUG_SCOPES_DISABLED'
Properties
- $context : array<int, mixed>
- $contextKeys : array<int, ContextKeyInterface>
- $span : object|null
- $spanContextKey : ContextKeyInterface
- $storage : ContextStorageInterface|ExecutionContextAwareInterface
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.
- setStorage() : void
- storage() : ContextStorageInterface|ExecutionContextAwareInterface
- with() : ContextInterface
- Returns a context with the given key set to the given value.
- withContextValue() : ContextInterface
- Returns a context with the given value set.
- __construct() : mixed
- debugScopesDisabled() : bool
Constants
OTEL_PHP_DEBUG_SCOPES_DISABLED
private
mixed
OTEL_PHP_DEBUG_SCOPES_DISABLED
= 'OTEL_PHP_DEBUG_SCOPES_DISABLED'
Properties
$context
private
array<int, mixed>
$context
= []
$contextKeys
private
array<int, ContextKeyInterface>
$contextKeys
= []
$span
private
object|null
$span
= null
$spanContextKey
private
static ContextKeyInterface
$spanContextKey
$storage
private
static ContextStorageInterface|ExecutionContextAwareInterface
$storage
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();
}
Return values
ScopeInterface —scope to detach the context and restore the previous context
createKey()
Creates a new context key.
public
static createKey(string $key) : ContextKeyInterface
Parameters
- $key : string
-
name of the key
Return values
ContextKeyInterface —created key
get()
Returns the value assigned to the given key.
public
get(ContextKeyInterface $key) : T|null
Parameters
- $key : ContextKeyInterface
-
key to get
Return values
T|null —value assigned to $key
, or null if no such value exists
getCurrent()
Returns the current context.
public
static getCurrent() : ContextInterface
Return values
ContextInterface —current context
setStorage()
public
static setStorage(ContextStorageInterface|ExecutionContextAwareInterface $storage) : void
Parameters
storage()
public
static storage() : ContextStorageInterface|ExecutionContextAwareInterface
Return values
ContextStorageInterface|ExecutionContextAwareInterfacewith()
Returns a context with the given key set to the given value.
public
with(ContextKeyInterface $key, mixed $value) : ContextInterface
Parameters
- $key : ContextKeyInterface
-
key to set
- $value : mixed
-
value to set
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
Return values
ContextInterface —a context with the given $value
__construct()
private
__construct() : mixed
debugScopesDisabled()
private
static debugScopesDisabled() : bool