switon/context

Runtime context isolation with scoped state for Switon Framework

Maintainers

Package info

github.com/switon-php/context

Documentation

pkg:composer/switon/context

Statistics

Installs: 3

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-05-09 16:52 UTC

This package is auto-updated.

Last update: 2026-05-09 16:54:21 UTC


README

Runtime context isolation and scoped state for Switon Framework.

Installation

composer require switon/context

Requirements: PHP 8.3+

Quick Start

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

License

MIT.