ldc-boutique-cnc-sable/domain/Models/ValueObjects/ShopperServiceCode.php

33 lines
720 B
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace Domain\Models\ValueObjects;
use Shared\DDD\Equatable;
final readonly class ShopperServiceCode implements \Stringable, Equatable
{
private const PATTERN = '/^\d{1,}$/';
public function __construct(
public readonly string $value
) {
if (! preg_match(self::PATTERN, $value)) {
throw new \DomainException(
"Invalid value '{$value}' does not match pattern " . self::PATTERN
);
}
}
public function __toString(): string
{
return $this->value;
}
public function equals(mixed $other): bool
{
return $other instanceof self && $this->value === $other->value;
}
}