75 lines
1.7 KiB
PHP
75 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Domain\Models\Entities;
|
|
|
|
use Domain\Models\ValueObjects\Brand\ArcadiaId;
|
|
use Domain\Models\ValueObjects\Brand\BrandCode;
|
|
use Domain\Models\ValueObjects\Brand\BrandId;
|
|
use Domain\Models\ValueObjects\Brand\BrandName;
|
|
use Ramsey\Uuid\Uuid;
|
|
use Shared\DDD\Model\AggregateRoot;
|
|
use Shared\DDD\Model\HasTimestampIdentifier;
|
|
|
|
/** @implements AggregateRoot<BrandId> */
|
|
final readonly class Brand implements AggregateRoot, HasTimestampIdentifier
|
|
{
|
|
private function __construct(
|
|
public BrandId $id,
|
|
public BrandName $name,
|
|
public BrandCode $code,
|
|
public ArcadiaId $arcadiaId,
|
|
) {
|
|
}
|
|
|
|
#[\Override]
|
|
public function id(): BrandId
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
#[\Override]
|
|
public function createdAt(): \DateTimeInterface
|
|
{
|
|
return $this->id->toDateTime();
|
|
}
|
|
|
|
public static function create(
|
|
BrandName $name,
|
|
BrandCode $code,
|
|
ArcadiaId $arcadiaId,
|
|
): self {
|
|
|
|
return new self(
|
|
id: new BrandId(Uuid::uuid7()),
|
|
name: $name,
|
|
code: $code,
|
|
arcadiaId: $arcadiaId,
|
|
);
|
|
}
|
|
|
|
public static function hydrate(
|
|
BrandId $id,
|
|
BrandName $name,
|
|
BrandCode $code,
|
|
ArcadiaId $arcadiaId,
|
|
): self {
|
|
return new self(
|
|
id: $id,
|
|
name: $name,
|
|
code: $code,
|
|
arcadiaId: $arcadiaId,
|
|
);
|
|
}
|
|
|
|
public function rename(BrandName $newName): self
|
|
{
|
|
return new self(
|
|
id: $this->id,
|
|
name: $newName,
|
|
code: $this->code,
|
|
arcadiaId: $this->arcadiaId,
|
|
);
|
|
}
|
|
}
|