1 | <?php |
||
11 | class SendgridTransport extends Transport |
||
12 | { |
||
13 | const MAXIMUM_FILE_SIZE = 7340032; |
||
14 | const SMTP_API_NAME = 'sendgrid/x-smtpapi'; |
||
15 | |||
16 | private $client; |
||
17 | private $options; |
||
18 | |||
19 | public function __construct(ClientInterface $client, $api_key) |
||
26 | |||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | public function send(Swift_Mime_Message $message, &$failedRecipients = null) |
||
56 | |||
57 | /** |
||
58 | * @param $data |
||
59 | * @param Swift_Mime_Message $message |
||
60 | */ |
||
61 | protected function setTo(&$data, Swift_Mime_Message $message) |
||
68 | |||
69 | /** |
||
70 | * @param $data |
||
71 | * @param Swift_Mime_Message $message |
||
72 | */ |
||
73 | protected function setCc(&$data, Swift_Mime_Message $message) |
||
80 | |||
81 | /** |
||
82 | * @param $data |
||
83 | * @param Swift_Mime_Message $message |
||
84 | */ |
||
85 | protected function setBcc(&$data, Swift_Mime_Message $message) |
||
92 | |||
93 | /** |
||
94 | * Get From Addresses. |
||
95 | * |
||
96 | * @param Swift_Mime_Message $message |
||
97 | * @return array |
||
98 | */ |
||
99 | protected function getFromAddresses(Swift_Mime_Message $message) |
||
108 | |||
109 | /** |
||
110 | * Set text contents. |
||
111 | * |
||
112 | * @param $data |
||
113 | * @param Swift_Mime_Message $message |
||
114 | */ |
||
115 | protected function setText(&$data, Swift_Mime_Message $message) |
||
124 | |||
125 | /** |
||
126 | * Set Attachment Files. |
||
127 | * |
||
128 | * @param $data |
||
129 | * @param Swift_Mime_Message $message |
||
130 | */ |
||
131 | protected function setAttachment(&$data, Swift_Mime_Message $message) |
||
142 | |||
143 | /** |
||
144 | * Set Sendgrid SMTP API |
||
145 | * |
||
146 | * @param $data |
||
147 | * @param Swift_Mime_Message $message |
||
148 | */ |
||
149 | protected function setSmtpApi(&$data, Swift_Mime_Message $message) |
||
160 | } |
||
161 |
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.