ldc-boutique-cnc-sable/shared/ValueObjects/CrmHashcode.php

36 lines
735 B
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Shared\ValueObjects;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Shared\Helpers\UuidHelper;
final readonly class CrmHashcode implements \Stringable
{
public string $value;
public function __construct(
UuidInterface $value,
) {
UuidHelper::validateUuid($value);
if (! UuidHelper::isV4($value)) {
throw new \DomainException('CrmHashcode is not a valid uuidv4');
}
$this->value = $value->toString();
}
public function __toString(): string
{
return $this->value;
}
public static function fromString(string $value): self
{
return new self(Uuid::fromString($value));
}
}