Change up the category entity.
This commit is contained in:
parent
d2406b419f
commit
d00d55371c
41
app/src/Domain/Entity/Category.php
Normal file
41
app/src/Domain/Entity/Category.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user