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(): self
Get the current ambient context.
self
Implements Context\ContextInterface
public function depth(): int
Get the current nesting depth of contexts.
int
Implements Context\ContextInterface
public function getClient(): ?OpenFGA\ClientInterface
Get the current client.
ClientInterface
| null
Implements Context\ContextInterface
public function getModel(): ?OpenFGA\Models\AuthorizationModelInterface|string|null
Get the current authorization model.
AuthorizationModelInterface
| null
| string
| null
Implements Context\ContextInterface
public function getPrevious(): ?self
Get the previous context in the stack.
self
| null
Implements Context\ContextInterface
public function getStore(): ?OpenFGA\Models\StoreInterface|string|null
Get the current store.
StoreInterface
| null
| string
| null
Implements Context\ContextInterface
public function hasContext(): bool
Check if an ambient context is currently active.
bool
Implements Context\ContextInterface
public function with(
callable $fn,
?OpenFGA\ClientInterface $client = NULL,
StoreInterface|string|null $store = NULL,
AuthorizationModelInterface|string|null $model = NULL,
): T
Execute 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