21 lines
410 B
PHP
21 lines
410 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Domain\Models\ValueObjects;
|
|
|
|
final readonly class Email
|
|
{
|
|
public function __construct(
|
|
public string $value
|
|
) {
|
|
$this->validate($value);
|
|
}
|
|
|
|
private function validate(string $email): void
|
|
{
|
|
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
throw new \DomainException('Invalid email address');
|
|
}
|
|
}
|
|
}
|