| 1 | <?php |
||
| 9 | * |
||
| 10 | * For the full copyright and license information, please view the LICENSE |
||
| 11 | * file that was distributed with this source code. |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace Domain\Model\Common\VO; |
||
| 15 | |||
| 16 | use Domain\Model\Common\Exception\InvalidEmail; |
||
| 17 | |||
| 18 | final class EmailField |
||
| 19 | { |
||
| 20 | private string $email; |
||
|
|
|||
| 21 | |||
| 22 | public function __construct(string $email) |
||
| 23 | { |
||
| 24 | if (!\filter_var($email, \FILTER_VALIDATE_EMAIL)) { |
||
| 25 | throw new InvalidEmail(); |
||
| 26 | } |
||
| 27 | $this->email = $email; |
||
| 28 | } |
||
| 29 | |||
| 30 | public static function fromString(string $email): self |
||
| 31 | { |
||
| 32 | return new self($email); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function getValue(): string |
||
| 36 | { |
||
| 37 | return $this->email; |
||
| 38 | } |
||
| 40 |