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

73 lines
1.4 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;
}
2024-05-30 01:56:42 +00:00
public function setEmail(string $email): User
{
$this->email = $email;
return $this;
}
public function getPassword(): string
{
return $this->password;
}
2024-05-30 01:56:42 +00:00
public function setPassword(string $password): User
{
$this->password = $password;
return $this;
}
public function getName(): string
{
return $this->name;
}
2024-05-30 01:56:42 +00:00
public function setName(string $name): User
{
2024-05-30 01:56:42 +00:00
$this->name = $name;
return $this;
}
/**
* @param string[] $props Properties of the User model
* @return User
*/
public static function fromArray(array $props): User
{
2024-05-30 01:56:42 +00:00
$user = new self($props['email'], $props['password'], $props['name']);
2024-06-03 01:26:10 +00:00
if (array_key_exists('id', $props)) {
$user->setId($props['id']);
}
2024-06-03 01:26:10 +00:00
if (array_key_exists('createdAt', $props)) {
2024-05-30 01:56:42 +00:00
$user->setCreatedAt($props['createdAt']);
}
2024-06-03 01:26:10 +00:00
if (array_key_exists('updatedAt', $props)) {
2024-05-30 01:56:42 +00:00
$user->setUpdatedAt($props['updatedAt']);
}
return $user;
}
}