1 | <?php |
||
11 | class MailmanFilesystemLogger extends AbstractMailmanLogger |
||
12 | { |
||
13 | /** |
||
14 | * Base path where email logs are stored. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $storagePath; |
||
19 | |||
20 | /** |
||
21 | * FileSystem adapter. |
||
22 | * |
||
23 | * @var Filesystem |
||
24 | */ |
||
25 | protected $fileSystem; |
||
26 | |||
27 | /** |
||
28 | * MailmanFilesystemLogger constructor. |
||
29 | */ |
||
30 | public function __construct() |
||
35 | |||
36 | /** |
||
37 | * Log given Swift_Mime_Message email message. |
||
38 | * |
||
39 | * @param MailmanSwiftMessageAdapter $message |
||
40 | * |
||
41 | * @return mixed |
||
42 | */ |
||
43 | public function log(MailmanSwiftMessageAdapter $message) |
||
57 | |||
58 | /** |
||
59 | * Generate a human readable HTML comment with message info. |
||
60 | * |
||
61 | * @param MailmanSwiftMessageAdapter $message |
||
62 | * |
||
63 | * @return string |
||
64 | */ |
||
65 | protected function getMessageInfo(MailmanSwiftMessageAdapter $message) |
||
80 | |||
81 | /** |
||
82 | * Get the HTML content for the log file. |
||
83 | * |
||
84 | * @param MailmanSwiftMessageAdapter $message |
||
85 | * |
||
86 | * @return string |
||
87 | */ |
||
88 | protected function getMessageHTMLContent(MailmanSwiftMessageAdapter $message) |
||
94 | |||
95 | /** |
||
96 | * Get the EML content for the log file. |
||
97 | * |
||
98 | * @param MailmanSwiftMessageAdapter $message |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | protected function getMessageEMLContent(MailmanSwiftMessageAdapter $message) |
||
106 | |||
107 | /** |
||
108 | * Get the path to the email log file. |
||
109 | * |
||
110 | * @param MailmanSwiftMessageAdapter $message |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | protected function getMessageLogFilePath(MailmanSwiftMessageAdapter $message) |
||
121 | |||
122 | /** |
||
123 | * Get the path to the email log directory. |
||
124 | * |
||
125 | * @param MailmanSwiftMessageAdapter $message |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | protected function getMessageLogDirectoryPath(MailmanSwiftMessageAdapter $message) |
||
135 | |||
136 | /** |
||
137 | * Create required directories for logging. |
||
138 | * |
||
139 | * @param MailmanSwiftMessageAdapter $message |
||
140 | */ |
||
141 | protected function prepareStorage(MailmanSwiftMessageAdapter $message) |
||
154 | } |
||
155 |
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.