Identity and tenant runtime contracts for Switon Framework.
composer require switon/principalRequirements: PHP 8.3+
namespace App\Controller;
use Switon\Core\Attribute\Autowired;
use Switon\Principal\IdentityInterface;
use Switon\Principal\TenantInterface;
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
MIT.