Last active
November 14, 2020 11:57
-
-
Save wazum/eec91ca32683c3e0ed03a0c55afc1465 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Something\Domain\ValueObject; | |
use Webmozart\Assert\Assert; | |
/** | |
* @Embeddable | |
*/ | |
final class EmailAddress implements NullableEmbeddable | |
{ | |
/** | |
* @Column(type="string", length=150, nullable=true) | |
*/ | |
private ?string $emailAddress = null; | |
public function __construct(string $emailAddress) | |
{ | |
$this->setEmailAddress($emailAddress); | |
} | |
public function getEmailAddress(): ?string | |
{ | |
return $this->emailAddress; | |
} | |
private function setEmailAddress(string $emailAddress): void | |
{ | |
Assert::maxLength($emailAddress, 150); | |
Assert::email($emailAddress); | |
$this->emailAddress = $emailAddress; | |
} | |
public function __toString(): string | |
{ | |
return (string) $this->getEmailAddress(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment