Files
Distributing-Carriers/src/Domain/ValueObjects/Email.php
2025-12-02 19:39:58 +03:30

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;
}
}