1 | <?php |
||
36 | class Message implements IMessage { |
||
37 | |||
38 | use ConvertAddresses; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $subject = ''; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | private $from = ''; |
||
49 | |||
50 | /** |
||
51 | * |
||
52 | * @var Horde_Mail_Rfc822_List |
||
53 | */ |
||
54 | private $to; |
||
55 | |||
56 | /** |
||
57 | * @var Horde_Mail_Rfc822_List |
||
58 | */ |
||
59 | private $cc; |
||
60 | |||
61 | /** |
||
62 | * @var Horde_Mail_Rfc822_List |
||
63 | */ |
||
64 | private $bcc; |
||
65 | |||
66 | /** |
||
67 | * @var IMessage |
||
68 | */ |
||
69 | private $repliedMessage = null; |
||
70 | |||
71 | /** |
||
72 | * @var array |
||
73 | */ |
||
74 | private $flags = []; |
||
75 | |||
76 | /** |
||
77 | * @var string |
||
78 | */ |
||
79 | private $content = ''; |
||
80 | |||
81 | /** |
||
82 | * @var File[] |
||
83 | */ |
||
84 | private $attachments = []; |
||
85 | |||
86 | /** |
||
87 | * @param string $list |
||
88 | * @return Horde_Mail_Rfc822_List |
||
89 | */ |
||
90 | 24 | public static function parseAddressList($list) { |
|
93 | |||
94 | 40 | public function __construct() { |
|
99 | |||
100 | /** |
||
101 | * Get the ID |
||
102 | * |
||
103 | * @return int|null |
||
104 | */ |
||
105 | public function getMessageId() { |
||
108 | |||
109 | /** |
||
110 | * Get all flags set on this message |
||
111 | * |
||
112 | * @return array |
||
113 | */ |
||
114 | 2 | public function getFlags() { |
|
117 | |||
118 | /** |
||
119 | * @param string[] $flags |
||
120 | */ |
||
121 | 2 | public function setFlags(array $flags) { |
|
124 | |||
125 | /** |
||
126 | * @return string |
||
127 | */ |
||
128 | 2 | public function getFrom() { |
|
131 | |||
132 | /** |
||
133 | * @param string $from |
||
134 | */ |
||
135 | 2 | public function setFrom($from) { |
|
138 | |||
139 | /** |
||
140 | * @return string |
||
141 | */ |
||
142 | 4 | public function getTo() { |
|
148 | |||
149 | /** |
||
150 | * @param Horde_Mail_Rfc822_List $to |
||
151 | */ |
||
152 | 2 | public function setTo(Horde_Mail_Rfc822_List $to) { |
|
155 | |||
156 | /** |
||
157 | * @param bool $assoc |
||
158 | * @return string[] |
||
159 | */ |
||
160 | 4 | public function getToList($assoc = false) { |
|
167 | |||
168 | /** |
||
169 | * @param bool $assoc |
||
170 | * @return Horde_Mail_Rfc822_List |
||
171 | */ |
||
172 | 4 | public function getCCList($assoc = false) { |
|
173 | 4 | if ($assoc) { |
|
174 | return $this->hordeListToAssocArray($this->cc); |
||
175 | } else { |
||
176 | 4 | return $this->hordeListToStringArray($this->cc); |
|
177 | } |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * @param Horde_Mail_Rfc822_List $cc |
||
182 | */ |
||
183 | 2 | public function setCC(Horde_Mail_Rfc822_List $cc) { |
|
186 | |||
187 | /** |
||
188 | * @param bool $assoc |
||
189 | * @return Horde_Mail_Rfc822_List |
||
190 | */ |
||
191 | 4 | public function getBCCList($assoc = false) { |
|
198 | |||
199 | /** |
||
200 | * @param Horde_Mail_Rfc822_List $bcc |
||
201 | */ |
||
202 | 2 | public function setBcc(Horde_Mail_Rfc822_List $bcc) { |
|
205 | |||
206 | /** |
||
207 | * @return IMessage |
||
208 | */ |
||
209 | 4 | public function getRepliedMessage() { |
|
212 | |||
213 | /** |
||
214 | * @param IMessage $message |
||
215 | */ |
||
216 | 2 | public function setRepliedMessage(IMessage $message) { |
|
219 | |||
220 | /** |
||
221 | * @return string |
||
222 | */ |
||
223 | 6 | public function getSubject() { |
|
226 | |||
227 | /** |
||
228 | * @param string $subject |
||
229 | */ |
||
230 | 4 | public function setSubject($subject) { |
|
233 | |||
234 | /** |
||
235 | * @return string |
||
236 | */ |
||
237 | 2 | public function getContent() { |
|
240 | |||
241 | /** |
||
242 | * @param string $content |
||
243 | */ |
||
244 | 2 | public function setContent($content) { |
|
247 | |||
248 | /** |
||
249 | * @return File[] |
||
250 | */ |
||
251 | 2 | public function getAttachments() { |
|
254 | |||
255 | /** |
||
256 | * @param File $file |
||
257 | */ |
||
258 | 2 | public function addAttachmentFromFiles(File $file) { |
|
267 | |||
268 | } |
||
269 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.