PHP code example of switon / principal
1. Go to this page and download the library: Download switon/principal library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
switon / principal example snippets
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,
];
}
}