switon / principal
Runtime contracts for resolved caller identity and tenant state after boundary resolution for Switon Framework
v1.0.0
2026-06-06 13:43 UTC
Requires
- php: >=8.3
- switon/core: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
README
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.