delete backend, starting over
This commit is contained in:
parent
babf9eb855
commit
f6a33cf620
51 changed files with 0 additions and 6655 deletions
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Shared\ValueObject;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
final readonly class EmailAddress
|
||||
{
|
||||
private string $normalized;
|
||||
|
||||
private const ERROR_MESSAGE = 'Invalid email address:';
|
||||
|
||||
public function __construct(string $email)
|
||||
{
|
||||
|
||||
$trimmed = trim($email);
|
||||
|
||||
if ($trimmed === '' || ! str_contains($trimmed, '@')) {
|
||||
throw new InvalidArgumentException(self::ERROR_MESSAGE . " $email");
|
||||
}
|
||||
|
||||
[$local, $domain] = explode('@', $trimmed, 2);
|
||||
$domain = mb_strtolower($domain);
|
||||
$normalized = $local . '@' . $domain;
|
||||
|
||||
if (filter_var($normalized, FILTER_VALIDATE_EMAIL) === false) {
|
||||
throw new InvalidArgumentException(self::ERROR_MESSAGE . " $email");
|
||||
}
|
||||
|
||||
$this->normalized = $normalized;
|
||||
}
|
||||
|
||||
public function value(): string
|
||||
{
|
||||
return $this->normalized;
|
||||
}
|
||||
|
||||
public function equals(self $other): bool
|
||||
{
|
||||
return $this->normalized === $other->normalized;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->normalized;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue