switon/principal

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

Maintainers

Package info

github.com/switon-php/principal

Documentation

pkg:composer/switon/principal

Statistics

Installs: 25

Dependents: 7

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-06-07 02:06:16 UTC


README

Principal CI PHP 8.3+

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

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

composer require switon/principal

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: https://docs.switon.dev/latest/principal

License

MIT.