API Context Context - evansims/openfga-php GitHub Wiki
Ambient Context Manager. Provides Python-style context management for PHP, allowing functions to access shared context without explicit parameter passing. This enables a more ergonomic API where client, store, and model can be set once and used implicitly by helper functions. Contexts support inheritance - child contexts automatically inherit values from their parent context unless explicitly overridden. This allows for flexible nesting where you can override just the pieces you need.
Table of Contents
OpenFGA\Context
- ContextInterface (interface)
Implements Context\ContextInterface
public function current(): selfGet the current ambient context.
self
Implements Context\ContextInterface
public function depth(): intGet the current nesting depth of contexts.
int — The number of active contexts in the stack
Implements Context\ContextInterface
public function getClient(): ClientInterface|nullGet the current client.
ClientInterface | null — The current client instance or null if not set
Implements Context\ContextInterface
public function getModel(): AuthorizationModelInterface|string|nullGet the current authorization model.
AuthorizationModelInterface | string | null — The current model instance, model ID, or null if not set
Implements Context\ContextInterface
public function getPrevious(): ?selfGet the previous context in the stack.
self | null
Implements Context\ContextInterface
public function getStore(): StoreInterface|string|nullGet the current store.
StoreInterface | string | null — The current store instance, store ID, or null if not set
Implements Context\ContextInterface
public function hasContext(): boolCheck if an ambient context is currently active.
bool — True if at least one context is active, false otherwise
Implements Context\ContextInterface
public function with(
callable $fn,
?OpenFGA\ClientInterface $client = NULL,
StoreInterface|string|null $store = NULL,
AuthorizationModelInterface|string|null $model = NULL,
): TExecute a callable within a new ambient context.
| Name | Type | Description |
|---|---|---|
$fn |
callable |
|
$client |
ClientInterface | null
|
Optional client for the context |
$store |
StoreInterface | string | null
|
Optional store for the context |
$model |
AuthorizationModelInterface | string | null
|
Optional model for the context |
T — The result of the callable execution