1 <?php
2 /* --------------------------------------------------------------
3 EmailContact.inc.php 2015-01-29 gm
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 MainFactory::load_class('EmailContactInterface');
13
14 /**
15 * Class EmailContact
16 *
17 * Represents a contact (sender/recipient) that participates in an email entity.
18 *
19 * @category System
20 * @package Email
21 * @subpackage Entities
22 */
23 class EmailContact implements EmailContactInterface
24 {
25 /**
26 * E-Mail address.
27 * @var EmailAddressInterface
28 */
29 protected $emailAddress;
30
31 /**
32 * E-Mail contact type.
33 * @var ContactTypeInterface
34 */
35 protected $contactType;
36
37 /**
38 * E-Mail contact name.
39 * @var ContactNameInterface
40 */
41 protected $contactName;
42
43
44 /**
45 * Constructor
46 *
47 * @param EmailAddressInterface $emailAddress (optional) E-Mail address.
48 * @param ContactNameInterface $contactName (optional) E-Mail contact type.
49 * @param ContactTypeInterface $contactType (optional) E-Mail contact name.
50 */
51 public function __construct(EmailAddressInterface $emailAddress = null,
52 ContactTypeInterface $contactType = null,
53 ContactNameInterface $contactName = null)
54 {
55 $this->emailAddress = $emailAddress;
56 $this->contactType = $contactType;
57 $this->contactName = $contactName;
58 }
59
60
61 /**
62 * Return contact information as a string.
63 *
64 * Example Output: 'John Doe <email@address.com>'
65 *
66 * @return string Converted string.
67 */
68 public function __toString()
69 {
70 $result = array();
71
72 if($this->contactName !== null)
73 {
74 $result[] = (string)$this->contactName;
75 }
76
77 if($this->emailAddress !== null)
78 {
79 $result[] = '<' . (string)$this->emailAddress . '>';
80 }
81
82 return implode(' ', $result);
83 }
84
85
86 /**
87 * Returns an email address.
88 *
89 * @return string E-Mail address.
90 */
91 public function getEmailAddress()
92 {
93 return (string)$this->emailAddress;
94 }
95
96
97 /**
98 * Sets an email address.
99 *
100 * @param EmailAddressInterface $emailAddress E-Mail address.
101 */
102 public function setEmailAddress(EmailAddressInterface $emailAddress)
103 {
104 $this->emailAddress = $emailAddress;
105 }
106
107
108 /**
109 * Returns the contact name of an email.
110 *
111 * @return string E-Mail contact name.
112 */
113 public function getContactName()
114 {
115 return (string)$this->contactName;
116 }
117
118
119 /**
120 * Sets the contact name of an email.
121 *
122 * @param ContactNameInterface $contactName E-Mail contact name.
123 */
124 public function setContactName(ContactNameInterface $contactName)
125 {
126 $this->contactName = $contactName;
127 }
128
129
130 /**
131 * Returns the contact type of an email.
132 *
133 * @return ContactTypeInterface E-Mail contact type.
134 */
135 public function getContactType()
136 {
137 return (string)$this->contactType;
138 }
139
140
141 /**
142 * Sets the contact type of an email.
143 *
144 * @param ContactTypeInterface $contactType E-Mail contact type.
145 */
146 public function setContactType(ContactTypeInterface $contactType)
147 {
148 $this->contactType = $contactType;
149 }
150 }