PHPackages                             switon/context - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. switon/context

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

switon/context
==============

Default context manager for request- and coroutine-scoped service-owned state for Switon Framework

v1.0.0(1mo ago)031MITPHPPHP &gt;=8.3CI passing

Since Jun 6Pushed 1mo agoCompare

[ Source](https://github.com/switon-php/context)[ Packagist](https://packagist.org/packages/switon/context)[ Docs](https://github.com/switon-php/context)[ RSS](/packages/switon-context/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (6)Versions (2)Used By (1)

Switon Context Package
======================

[](#switon-context-package)

[![CI](https://camo.githubusercontent.com/e47e33d2bf21476fafe41566a7dcad67867a427d2a100dfcf4852175cb775672/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f737769746f6e2d7068702f636f6e746578742f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d4349)](https://github.com/switon-php/context/actions/workflows/ci.yml) [![PHP 8.3+](https://camo.githubusercontent.com/c03f51341eebaefabbf137e291b20523fc74b4ffd084406d88524d266d95085d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d373737424234)](https://www.php.net/)

Switon's runtime state manager for `ContextAware` components, including HTTP request isolation and coroutine sharing.

Highlights
----------

[](#highlights)

- **Request isolation:** mutable state stays out of long-lived services.
- **Automatic context binding:** `getContext()` resolves the matching context for each component.
- **Coroutine sharing:** child coroutines can inherit or reset context as needed.
- **Lifecycle events:** child-context creation and propagation are observable.
- **Scoped runtime state:** `ContextManager` keeps the active context available for the current request or coroutine.

Installation
------------

[](#installation)

```
composer require switon/context
```

Quick Start
-----------

[](#quick-start)

```
use Switon\Core\Attribute\Autowired;
use Switon\Core\ContextAware;
use Switon\Core\ContextManagerInterface;

final class RequestStateContext
{
    public array $vars = [];
}

final class RequestState implements ContextAware
{
    #[Autowired] protected ContextManagerInterface $contextManager;

    public function getContext(): RequestStateContext
    {
        return $this->contextManager->getContext($this);
    }

    public function remember(string $key, mixed $value): void
    {
        $this->getContext()->vars[$key] = $value;
    }
}
```

Docs:

License
-------

[](#license)

MIT.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance90

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

48d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc0f20ad15b0ae9fbf9c6e2cd3008692b0c88a877ec8d3e0119211314bf86fc8?d=identicon)[switon](/maintainers/switon)

---

Top Contributors

[![switon-php](https://avatars.githubusercontent.com/u/247358032?v=4)](https://github.com/switon-php "switon-php (1 commits)")

---

Tags

contextruntimescopeswitonContextruntimescopeswiton

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/switon-context/health.svg)

```
[![Health](https://phpackages.com/badges/switon-context/health.svg)](https://phpackages.com/packages/switon-context)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[symfony/event-dispatcher-contracts

Generic abstractions related to dispatching event

3.4k807.0M645](/packages/symfony-event-dispatcher-contracts)[deptrac/deptrac

Deptrac is a static code analysis tool that helps to enforce rules for dependencies between software layers.

3.0k8.8M207](/packages/deptrac-deptrac)[phpro/soap-client

A general purpose SoapClient library

8896.1M54](/packages/phpro-soap-client)[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.5k1.5M107](/packages/mcp-sdk)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

326123.0k1](/packages/cognesy-instructor-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
