This change improves the handling of hashcodes by utilizing the CrmHashcode value object.
35 lines
735 B
PHP
35 lines
735 B
PHP
<?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));
|
|
}
|
|
}
|