83 lines
1.7 KiB
PHP
83 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Slovocast\Domain\Entity;
|
|
|
|
use DateTimeImmutable;
|
|
use DateTime;
|
|
use Slovocast\Domain\Entity;
|
|
|
|
class User
|
|
{
|
|
use Entity;
|
|
|
|
public function __construct(
|
|
private string $email,
|
|
private string $password,
|
|
private string $name
|
|
) { }
|
|
|
|
public function getEmail(): string
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
public function setEmail(string $email): User
|
|
{
|
|
$this->email = $email;
|
|
return $this;
|
|
}
|
|
|
|
public function getPassword(): string
|
|
{
|
|
return $this->password;
|
|
}
|
|
|
|
public function setPassword(string $password): User
|
|
{
|
|
$this->password = $password;
|
|
return $this;
|
|
}
|
|
|
|
public function getName(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(string $name): User
|
|
{
|
|
$this->name = $name;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param array $props Properties of the User model
|
|
* @return User
|
|
*/
|
|
public static function fromArray(array $props): User
|
|
{
|
|
$user = new self($props['email'], $props['password'], $props['name']);
|
|
|
|
if (isset($props['id'])) {
|
|
$user->setId($props['id']);
|
|
}
|
|
|
|
if (isset($props['createdAt'])) {
|
|
if (is_string($props['createdAt'])) {
|
|
$props['createdAt'] = new DateTimeImmutable($props['createdAt']);
|
|
}
|
|
|
|
$user->setCreatedAt($props['createdAt']);
|
|
}
|
|
|
|
if (isset($props['updatedAt'])) {
|
|
if (is_string($props['updatedAt'])) {
|
|
$props['updatedAt'] = new DateTime($props['updatedAt']);
|
|
}
|
|
|
|
$user->setUpdatedAt($props['updatedAt']);
|
|
}
|
|
|
|
return $user;
|
|
}
|
|
}
|