ldc-cocotte/shared/DDD/EntityId.php

31 lines
655 B
PHP
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace Shared\DDD;
use Ramsey\Uuid\UuidInterface;
use Shared\Helpers\UuidHelper;
2026-06-14 21:32:07 +02:00
abstract readonly class EntityId implements \Stringable, Equatable
{
public function __construct(
public UuidInterface $value,
) {
if (! UuidHelper::isV7($this->value)) {
throw new \DomainException('value must be a valid UUID v7');
}
}
2026-06-14 21:32:07 +02:00
#[\Override]
public function __toString(): string
{
return $this->value->toString();
}
public function equals(mixed $other): bool
{
return $other instanceof self && $this->value->equals($other->value);
}
}