mirror of
https://gitlab.com/izyim/prototypes/ddd-example.git
synced 2026-08-25 07:24:13 +00:00
Create User Zone
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Src\Zone\User\Domain\Model\ValueObjects;
|
||||
|
||||
use Src\Common\Domain\Exceptions\IncorrectEmailFormatException;
|
||||
use Src\Common\Domain\Exceptions\RequiredException;
|
||||
|
||||
final class Email implements \JsonSerializable
|
||||
{
|
||||
private string $email;
|
||||
|
||||
public function __construct(?string $email, $isOptional = false)
|
||||
{
|
||||
if (!$email && !$isOptional) {
|
||||
throw new RequiredException('email');
|
||||
}
|
||||
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new IncorrectEmailFormatException();
|
||||
}
|
||||
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user