Skip to content

switon-php/context

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Switon Context Package

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages