44 خطوط
1.5 KiB
PHP
44 خطوط
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Identity\Application;
|
|
|
|
use App\Models\User;
|
|
use App\Modules\System\Domain\DeploymentCapabilities;
|
|
|
|
final readonly class AuthenticatedUserPayload
|
|
{
|
|
public function __construct(
|
|
private RolePermissions $permissions,
|
|
private DeploymentCapabilities $deployment,
|
|
) {}
|
|
|
|
/** @return array<string, mixed> */
|
|
public function make(User $user): array
|
|
{
|
|
$user->loadMissing('organization');
|
|
|
|
return [
|
|
'id' => $user->getKey(),
|
|
'name' => $user->name,
|
|
'email' => $user->email,
|
|
'role' => $user->role->value,
|
|
'status' => $user->status->value,
|
|
'locale' => $user->locale,
|
|
'timezone' => $user->timezone,
|
|
'permissions' => array_map(fn ($permission) => $permission->value, $this->permissions->for($user->role)),
|
|
'organization' => $user->organization ? [
|
|
'id' => $user->organization->getKey(),
|
|
'name' => $user->organization->name,
|
|
'slug' => $user->organization->slug,
|
|
'defaultLocale' => $user->organization->default_locale,
|
|
'timezone' => $user->organization->timezone,
|
|
] : null,
|
|
'deployment' => [
|
|
'mode' => $this->deployment->mode()->value,
|
|
'supportsMultipleOrganizations' => $this->deployment->supportsMultipleOrganizations(),
|
|
'exposesSubscriptionManagement' => $this->deployment->exposesSubscriptionManagement(),
|
|
],
|
|
];
|
|
}
|
|
}
|