This repository was archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathEmail.php
More file actions
125 lines (103 loc) · 2.59 KB
/
Email.php
File metadata and controls
125 lines (103 loc) · 2.59 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems.
*
* @see https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository
*
* @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com)
* @license https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence)
*/
declare(strict_types=1);
namespace LooplineSystems\CloseIoApiWrapper\Model;
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\RFCValidation;
use LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException;
use LooplineSystems\CloseIoApiWrapper\Library\JsonSerializableHelperTrait;
use LooplineSystems\CloseIoApiWrapper\Library\ObjectHydrateHelperTrait;
class Email implements \JsonSerializable
{
use ObjectHydrateHelperTrait;
use JsonSerializableHelperTrait;
const EMAIL_TYPE_HOME = 'home';
const EMAIL_TYPE_OFFICE = 'office';
const EMAIL_TYPE_DIRECT = 'direct';
/**
* @var string
*/
private $email;
/**
* @var string
*/
private $type;
/**
* @var object
*/
private $validator;
/**
* @var object
*/
private $validation;
/**
* @param array $data
*
* @throws InvalidParamException
*/
public function __construct(array $data = null)
{
if ($data) {
$this->hydrate($data);
}
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param string $email
*
* @return $this
*
* @throws InvalidParamException
*/
public function setEmail($email)
{
if (!$this->_getValidator()->isValid($email, $this->_getValidation())) {
throw new InvalidParamException('Invalid email format: "' . $email . '"');
} else {
$this->email = $email;
}
return $this;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @param string $type
*
* @return $this
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
private function _getValidator()
{
if (is_null($this->validator))
$this->validator = new EmailValidator();
return $this->validator;
}
private function _getValidation()
{
if (is_null($this->validation))
$this->validation = new RFCValidation();
return $this->validation;
}
}