feat: introduce user management events
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXC\User\Event;
|
||||
|
||||
use KTXF\Event\Event;
|
||||
|
||||
abstract class UserEvent extends Event
|
||||
{
|
||||
final public function __construct(
|
||||
private readonly string $userIdentifier,
|
||||
private readonly string $userIdentity,
|
||||
private readonly string $userLabel,
|
||||
private readonly bool $userEnabled,
|
||||
private readonly array $userRoles,
|
||||
private readonly string $tenantIdentifier,
|
||||
private readonly ?string $actorIdentifier = null,
|
||||
) {
|
||||
if ($userIdentifier === '') {
|
||||
throw new \InvalidArgumentException('User lifecycle events require a user ID.');
|
||||
}
|
||||
if ($userIdentity === '') {
|
||||
throw new \InvalidArgumentException('User lifecycle events require a user identity.');
|
||||
}
|
||||
if ($tenantIdentifier === '') {
|
||||
throw new \InvalidArgumentException('User lifecycle events require a tenant ID.');
|
||||
}
|
||||
parent::__construct(
|
||||
static::class,
|
||||
[
|
||||
'identifier' => $userIdentifier,
|
||||
'identity' => $userIdentity,
|
||||
'label' => $userLabel,
|
||||
'roles' => $userRoles,
|
||||
'enabled' => $userEnabled,
|
||||
],
|
||||
$tenantIdentifier,
|
||||
$actorIdentifier,
|
||||
);
|
||||
}
|
||||
|
||||
public static function fromUser(
|
||||
array $user,
|
||||
string $tenantIdentifier,
|
||||
?string $actorIdentifier = null,
|
||||
): static {
|
||||
return new static(
|
||||
(string) ($user['uid'] ?? ''),
|
||||
(string) ($user['identity'] ?? ''),
|
||||
(string) ($user['label'] ?? $user['identity'] ?? ''),
|
||||
(bool) ($user['enabled'] ?? true),
|
||||
array_values((array) ($user['roles'] ?? [])),
|
||||
$tenantIdentifier,
|
||||
$actorIdentifier,
|
||||
);
|
||||
}
|
||||
|
||||
public function userIdentifier(): string
|
||||
{
|
||||
return $this->userIdentifier;
|
||||
}
|
||||
|
||||
public function userIdentity(): string
|
||||
{
|
||||
return $this->userIdentity;
|
||||
}
|
||||
|
||||
public function userLabel(): string
|
||||
{
|
||||
return $this->userLabel;
|
||||
}
|
||||
|
||||
public function userRoles(): array
|
||||
{
|
||||
return $this->userRoles;
|
||||
}
|
||||
|
||||
public function userEnabled(): bool
|
||||
{
|
||||
return $this->userEnabled;
|
||||
}
|
||||
|
||||
public function actorIdentifier(): ?string
|
||||
{
|
||||
return $this->actorIdentifier;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user