-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEmail.php
More file actions
42 lines (33 loc) · 712 Bytes
/
Email.php
File metadata and controls
42 lines (33 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* Created by PhpStorm.
* User: chentao
* Date: 2019/3/22
* Time: 3:33 PM
*/
namespace Helper;
final class Email
{
private $email;
private function __construct($email)
{
$this->ensureIsValidEmail($email);
$this->email = $email;
}
public static function fromString($email)
{
return new self($email);
}
public function __toString()
{
return $this->email;
}
private function ensureIsValidEmail($email)
{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new \InvalidArgumentException(
sprintf('"%s" is not a valid email address', $email)
);
}
}
}