Skip to content

Instantly share code, notes, and snippets.

@wazum
Last active November 14, 2020 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wazum/eec91ca32683c3e0ed03a0c55afc1465 to your computer and use it in GitHub Desktop.
Save wazum/eec91ca32683c3e0ed03a0c55afc1465 to your computer and use it in GitHub Desktop.
<?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