37 lines
735 B
PHP
37 lines
735 B
PHP
<?php
|
|
|
|
namespace DistributingCarriers\Domain\ValueObjects;
|
|
|
|
use DistributingCarriers\Infrastructure\Exceptions\DomainException;
|
|
|
|
final class Email
|
|
{
|
|
private string $value;
|
|
|
|
public function __construct(string $email)
|
|
{
|
|
$email = strtolower(trim($email));
|
|
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
throw new DomainException("Invalid email address: {$email}");
|
|
}
|
|
|
|
$this->value = $email;
|
|
}
|
|
|
|
public function getValue(): string
|
|
{
|
|
return $this->value;
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return $this->value;
|
|
}
|
|
|
|
public function equals(Email $other): bool
|
|
{
|
|
return $this->value === $other->value;
|
|
}
|
|
}
|