chore: complete update
This commit is contained in:
31
src/Domain/ValueObjects/EmailAddress.php
Normal file
31
src/Domain/ValueObjects/EmailAddress.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Domain\ValueObjects;
|
||||
|
||||
final readonly class EmailAddress
|
||||
{
|
||||
public function __construct(
|
||||
public string $value
|
||||
) {
|
||||
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new \InvalidArgumentException("Invalid email address: {$value}");
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getDomain(): string
|
||||
{
|
||||
return substr($this->value, strpos($this->value, '@') + 1);
|
||||
}
|
||||
|
||||
public function getLocalPart(): string
|
||||
{
|
||||
return substr($this->value, 0, strpos($this->value, '@'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user