2026-09-30 11:20:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Domain\Models\ValueObjects;
|
|
|
|
|
|
|
|
|
|
use Stringable;
|
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
|
|
|
|
|
|
final readonly class PhoneNumber implements Stringable
|
|
|
|
|
{
|
|
|
|
|
public function __construct(public string $value)
|
|
|
|
|
{
|
|
|
|
|
$trimmed = trim($value);
|
|
|
|
|
Assert::stringNotEmpty($trimmed, 'Phone number cannot be empty.');
|
|
|
|
|
Assert::minLength($trimmed, 4, 'Phone number must have at least 4 characters.');
|
|
|
|
|
Assert::maxLength($trimmed, 30, 'Phone number cannot exceed 30 characters.');
|
2026-09-30 11:59:57 +02:00
|
|
|
Assert::regex($trimmed, '/^(tel:)?\+?[0-9\s\-\.\(\)]+$/', 'Phone number format is invalid.');
|
2026-09-30 11:20:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[\Override]
|
|
|
|
|
public function __toString(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->value;
|
|
|
|
|
}
|
|
|
|
|
}
|