ldc-boutique-cnc-sable/domain/Models/ValueObjects/Matricule.php
2026-10-27 09:58:12 +01:00

31 lines
651 B
PHP

<?php
declare(strict_types=1);
namespace Domain\Models\ValueObjects;
use Shared\DDD\Equatable;
final readonly class Matricule implements \Stringable, Equatable
{
public string $value;
public function __construct(string $matricule)
{
if (! preg_match('/^\d{7}$/', $matricule)) {
throw new \DomainException('Matricule must be a 7-digit string');
}
$this->value = $matricule;
}
public function __toString(): string
{
return $this->value;
}
public function equals(mixed $other): bool
{
return $other instanceof self && $this->value === $other->value;
}
}