PHPackages                             switon/principal - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. switon/principal

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

switon/principal
================

Runtime contracts for resolved caller identity and tenant state after boundary resolution for Switon Framework

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

Since Jun 6Pushed 2mo agoCompare

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

READMEChangelogDependencies (4)Versions (2)Used By (7)

Switon Principal Package
========================

[](#switon-principal-package)

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

Switon's request-local identity and tenant state for auth checks and tenant-aware flows.

Highlights
----------

[](#highlights)

- **Request-scoped identity:** each request keeps its own guest or authenticated user state.
- **Tenant state:** the resolved tenant stays available for later checks without re-resolving it.
- **Explicit boundary writes:** auth and tenant resolution can seed or clear the current request state.
- **Stable tenant key:** apps can keep a public tenant code separate from the internal tenant ID.
- **Mutable request state:** identity and tenant data stay local to the current request.

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

[](#installation)

```
composer require switon/principal
```

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

[](#quick-start)

```
use Switon\Core\Attribute\Autowired;
use Switon\Principal\IdentityInterface;
use Switon\Principal\TenantInterface;

final class AuthBoundary
{
    #[Autowired] protected IdentityInterface $identity;
    #[Autowired] protected TenantInterface $tenant;

    public function bootstrap(): void
    {
        $this->identity->set(7, 'mark', ['admin']);
        $this->tenant->set('acme', 'acme');
    }
}

final class ProfileController
{
    #[Autowired] protected IdentityInterface $identity;
    #[Autowired] protected TenantInterface $tenant;

    public function indexAction(): array
    {
        return [
            'user_id' => $this->identity->isGuest() ? null : $this->identity->getId(),
            'tenant' => $this->tenant->hasTenant() ? $this->tenant->getCode() : null,
        ];
    }
}
```

Docs:

License
-------

[](#license)

MIT.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance87

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community13

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 (7 commits)")

---

Tags

identityprincipalswitontenantidentitytenantswitonprincipal

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[league/oauth2-client

OAuth 2.0 Client Library

3.8k128.7M1.3k](/packages/league-oauth2-client)[league/oauth1-client

OAuth 1.0 Client Library

995110.3M121](/packages/league-oauth1-client)[onelogin/php-saml

PHP SAML Toolkit

1.3k47.8M144](/packages/onelogin-php-saml)[facile-it/php-openid-client

OpenID (OIDC) Client

44663.0k13](/packages/facile-it-php-openid-client)[adam-paterson/oauth2-stripe

Stripe OAuth 2.0 Client Provider for The PHP League OAuth2-Client

172.6M4](/packages/adam-paterson-oauth2-stripe)[telesign/telesign

TeleSign SDK

182.1M3](/packages/telesign-telesign)

PHPackages © 2026

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