Runtime context isolation and scoped state for Switon Framework.
composer require switon/contextRequirements: PHP 8.3+
use Switon\Core\Attribute\Autowired;
use Switon\Core\ContextAware;
use Switon\Core\ContextManagerInterface;
class ExampleViewContext
{
public array $vars = [];
}
class ExampleView implements ContextAware
{
#[Autowired] protected ContextManagerInterface $contextManager;
public function getContext(): ExampleViewContext
{
return $this->contextManager->getContext($this);
}
public function setVar(string $name, mixed $value): void
{
$this->getContext()->vars[$name] = $value;
}
}Docs: https://docs.switon.dev/latest/context
MIT.