unkown commit
This commit is contained in:
36
src/Domain/ValueObjects/Email.php
Normal file
36
src/Domain/ValueObjects/Email.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user