Код: Выделить всё
class User
{
public const STATUS_ACTIVE = 1;
public const STATUS_WAIT = 2;
public const STATUS_BLOCKED = 3;
protected $id;
protected $login;
protected $authKey;
protected $passwordHash;
protected $email;
protected $status;
protected $createdAt;
protected $updatedAt;
public function __construct(
$id,
string $login,
string $email,
string $passwordHash,
string $authKey,
int $status,
\DateTimeImmutable $createdAt,
\DateTimeImmutable $updatedAt
)
{
$this->id = $id;
$this->login = $login;
$this->email = $email;
$this->passwordHash = $passwordHash;
$this->authKey = $authKey;
$this->status = $status;
$this->createdAt = $createdAt;
$this->updatedAt = $updatedAt;
}
public function getId()
{
return $this->id;
}
public function getLogin(): string
{
return $this->login;
}
public function getAuthKey(): string
{
return $this->authKey;
}
public function getEmail(): string
{
return $this->email;
}
public function getStatus()
{
return $this->status;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): \DateTimeImmutable
{
return $this->updatedAt;
}
public function isActive()
{
return $this->status === self::STATUS_ACTIVE;
}
public function isWait()
{
return $this->status === self::STATUS_WAIT;
}
public function isBlocked()
{
return $this->status === self::STATUS_BLOCKED;
}
public function changeLogin(string $login)
{
if($login !== $this->login) {
$this->login = $login;
$this->flashEvent(new UserChangeLoginEvent($this));
}
}
public function changeEmail(string $email)
{
if($email !== $this->email) {
$this->email = $email;
$this->flashEvent(new UserChangeEmailEvent($this));
}
}
public function changePassword(string $password, PasswordService $service)
{
if(!$service->validatePassword($password, $this->passwordHash)) {
$this->passwordHash = $service->hashPassword($password);
$this->flashEvent(new UserChangePasswordEvent($this));
}
}
public function changeStatus(int $status)
{
if($status !== $this->status) {
$this->status = $status;
}
}
public function isPasswordRelevant(string $password, PasswordService $service): bool
{
return $service->validatePassword($password, $this->passwordHash);
}
public function activate()
{
$this->status = self::STATUS_ACTIVE;
}
public function waiting()
{
$this->status = self::STATUS_WAIT;
}
public function block()
{
$this->status = self::STATUS_BLOCKED;
}
}
Возникает вопрос, каким образом лучше контролировать список измененных полей сущности для обновления?