Files
Starseed/src/Shared/Domain/ValueObject/Email.php

32 lines
624 B
PHP

<?php
declare(strict_types=1);
namespace App\Shared\Domain\ValueObject;
use InvalidArgumentException;
final readonly class Email
{
public readonly string $value;
public function __construct(string $value)
{
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException(sprintf('"%s" is not a valid email address.', $value));
}
$this->value = $value;
}
public function __toString(): string
{
return $this->value;
}
public function equals(self $other): bool
{
return $this->value === $other->value;
}
}