76 lines
1.7 KiB
PHP
76 lines
1.7 KiB
PHP
|
|
<?php
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace MailAccountAdmin\Models;
|
||
|
|
|
||
|
|
use DateTimeImmutable;
|
||
|
|
|
||
|
|
class AdminUser
|
||
|
|
{
|
||
|
|
/** @var int */
|
||
|
|
private $id;
|
||
|
|
/** @var string */
|
||
|
|
private $username;
|
||
|
|
/** @var string */
|
||
|
|
private $passwordHash;
|
||
|
|
/** @var bool */
|
||
|
|
private $active;
|
||
|
|
/** @var DateTimeImmutable */
|
||
|
|
private $createdAt;
|
||
|
|
/** @var DateTimeImmutable */
|
||
|
|
private $modifiedAt;
|
||
|
|
|
||
|
|
private function __construct(int $id, string $username, string $passwordHash, bool $isActive,
|
||
|
|
DateTimeImmutable $createdAt, DateTimeImmutable $modifiedAt)
|
||
|
|
{
|
||
|
|
$this->id = $id;
|
||
|
|
$this->username = $username;
|
||
|
|
$this->passwordHash = $passwordHash;
|
||
|
|
$this->active = $isActive;
|
||
|
|
$this->createdAt = $createdAt;
|
||
|
|
$this->modifiedAt = $modifiedAt;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function createFromArray(array $data): self
|
||
|
|
{
|
||
|
|
return new self(
|
||
|
|
(int)$data['admin_id'],
|
||
|
|
$data['username'],
|
||
|
|
$data['password'],
|
||
|
|
$data['is_active'] === '1',
|
||
|
|
new DateTimeImmutable($data['created_at']),
|
||
|
|
new DateTimeImmutable($data['modified_at']),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getId(): int
|
||
|
|
{
|
||
|
|
return $this->id;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getUsername(): string
|
||
|
|
{
|
||
|
|
return $this->username;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getPasswordHash(): string
|
||
|
|
{
|
||
|
|
return $this->passwordHash;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isActive(): bool
|
||
|
|
{
|
||
|
|
return $this->active;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getCreatedAt(): DateTimeImmutable
|
||
|
|
{
|
||
|
|
return $this->createdAt;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getModifiedAt(): DateTimeImmutable
|
||
|
|
{
|
||
|
|
return $this->modifiedAt;
|
||
|
|
}
|
||
|
|
}
|