Add the Entity trait to the channel.

This commit is contained in:
Dave Smith-Hayes 2024-05-29 21:44:03 -04:00
parent 5a86bb3579
commit 8d7bcd0c2a

View File

@ -2,10 +2,13 @@
namespace Slovocast\Domain\Entity; namespace Slovocast\Domain\Entity;
use Slovocast\Domain\Entity;
class Channel class Channel
{ {
use Entity;
public function __construct( public function __construct(
private readonly ?int $id,
private string $name, private string $name,
private ?string $description = '', private ?string $description = '',
private ?string $link = '', private ?string $link = '',
@ -45,8 +48,7 @@ class Channel
*/ */
public static function fromArray(array $props): Channel public static function fromArray(array $props): Channel
{ {
return self( $channel = new self(
$props['id'] ?? null,
$props['name'], $props['name'],
$props['description'] ?? '', $props['description'] ?? '',
$props['link'] ?? '', $props['link'] ?? '',
@ -54,5 +56,19 @@ class Channel
$props['copyright'] ?? '', $props['copyright'] ?? '',
$props['explicit'] ?? false $props['explicit'] ?? false
); );
if ($props['id']) {
$channel->setId($props['id']);
}
if ($props['createdAt']) {
$channel->setCreatedAt($props['createdAt']);
}
if ($props['updatedAt']) {
$channel->setUpdatedAt($props['updatedAt']);
}
return $channel;
} }
} }