33 lines
731 B
PHP
33 lines
731 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Domain\Models\ValueObjects;
|
||
|
|
|
||
|
|
use Shared\DDD\Equatable;
|
||
|
|
|
||
|
|
final readonly class ShopperEstablishmentCode implements \Stringable, Equatable
|
||
|
|
{
|
||
|
|
private const PATTERN = '/^[\dA-Z]{2,}$/';
|
||
|
|
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
}
|