init
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Account;
|
||||
|
||||
readonly class UserProfile
|
||||
{
|
||||
|
||||
function __construct(
|
||||
public string $id,
|
||||
public string $name,
|
||||
public string $email,
|
||||
public Role $role,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public static function fromUser(User $user): UserProfile
|
||||
{
|
||||
return new UserProfile(
|
||||
$user->id,
|
||||
$user->name,
|
||||
$user->email,
|
||||
$user->role,
|
||||
);
|
||||
}
|
||||
|
||||
public static function fromArray(array $data): ?UserProfile
|
||||
{
|
||||
if (empty($data)) {
|
||||
return null;
|
||||
}
|
||||
return new UserProfile(
|
||||
id: data_get($data, "id"),
|
||||
name: data_get($data, "name"),
|
||||
email: data_get($data, "email"),
|
||||
role: data_get($data, "role"),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user