2024-05-14 02:06:01 +00:00
|
|
|
<?php
|
|
|
|
|
2024-05-24 01:24:57 +00:00
|
|
|
namespace Slovocast\Domain\Entity;
|
|
|
|
|
|
|
|
use Slovocast\Domain\Entity;
|
2024-05-14 02:06:01 +00:00
|
|
|
|
|
|
|
class User
|
|
|
|
{
|
2024-05-24 01:24:57 +00:00
|
|
|
use Entity;
|
|
|
|
|
2024-05-14 02:06:01 +00:00
|
|
|
public function __construct(
|
|
|
|
private string $email,
|
|
|
|
private string $password,
|
|
|
|
private string $name
|
2024-05-24 01:24:57 +00:00
|
|
|
) { }
|
2024-05-14 02:06:01 +00:00
|
|
|
|
|
|
|
public function getEmail(): string
|
|
|
|
{
|
|
|
|
return $this->email;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPassword(): string
|
|
|
|
{
|
|
|
|
return $this->password;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(): string
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the `id` property exists, we can assume this entity already exists.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isNew(): bool
|
|
|
|
{
|
2024-05-24 01:24:57 +00:00
|
|
|
return (bool) $this->getId();
|
2024-05-14 02:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string[] $props Properties of the User model
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public static function fromArray(array $props): User
|
|
|
|
{
|
2024-05-24 01:24:57 +00:00
|
|
|
$user = new self(
|
2024-05-14 02:06:01 +00:00
|
|
|
$props['email'],
|
|
|
|
$props['password'],
|
|
|
|
$props['name']
|
|
|
|
);
|
2024-05-24 01:24:57 +00:00
|
|
|
|
|
|
|
if ($props['id']) {
|
|
|
|
$user->setId($props['id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$user->setCreatedAt($props['createdAt']);
|
|
|
|
$user->setUpdatedAt($props['updatedAt']);
|
|
|
|
|
|
|
|
return $user;
|
2024-05-14 02:06:01 +00:00
|
|
|
}
|
|
|
|
}
|