Change up the category entity.

This commit is contained in:
Dave Smith-Hayes 2024-11-11 20:38:22 +00:00
parent d2406b419f
commit d00d55371c

View File

@ -0,0 +1,41 @@
<?php
namespace Slovocast\Domain\Entity;
use Slovocast\Domain\Entity as EntityTrait;
class Category
{
use EntityTrait;
public function __construct(
private string $name
) { }
public function getName(): string
{
return $this->name;
}
/**
* @param array $props Key is each property of the entity
*/
public static function fromArray(array $props): self
{
$category = new self($props['name']);
if ($props['id']) {
$category->setId($props['id']);
}
if ($props['createdAt']) {
$category->setCreatedAt($props['createdAt']);
}
if ($props['updatedAt']) {
$category->setUpdatedAt($props['updatedAt']);
}
return $category;
}
}