slovocast/app/src/Domain/Entity/User.php

64 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace Slovocast\Domain\Entity;
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 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
{
return (bool) $this->getId();
}
/**
* @param string[] $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 ($props['id']) {
$user->setId($props['id']);
}
$user->setCreatedAt($props['createdAt']);
$user->setUpdatedAt($props['updatedAt']);
return $user;
}
}