1 | <?php |
||
9 | class PostmarkTransport extends Transport |
||
10 | { |
||
11 | /** |
||
12 | * Guzzle client instance. |
||
13 | * |
||
14 | * @var \GuzzleHttp\ClientInterface |
||
15 | */ |
||
16 | protected $client; |
||
17 | |||
18 | /** |
||
19 | * The Postmark API key. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $key; |
||
24 | |||
25 | /** |
||
26 | * The Postmark API end-point. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $url = 'https://api.postmarkapp.com/email'; |
||
31 | |||
32 | /** |
||
33 | * Create a new Postmark transport instance. |
||
34 | * |
||
35 | * @param \GuzzleHttp\ClientInterface $client |
||
36 | * @param string $key |
||
37 | * |
||
38 | * @return void |
||
39 | */ |
||
40 | 5 | public function __construct(ClientInterface $client, $key) |
|
45 | |||
46 | /** |
||
47 | * Send the given Message. |
||
48 | * |
||
49 | * Recipient/sender data will be retrieved from the Message API. |
||
50 | * The return value is the number of recipients who were accepted for delivery. |
||
51 | * |
||
52 | * @param Swift_Mime_Message $message |
||
53 | * @param string[] $failedRecipients An array of failures by-reference |
||
54 | * |
||
55 | * @return int |
||
56 | */ |
||
57 | 1 | public function send(Swift_Mime_Message $message, &$failedRecipients = null) |
|
67 | |||
68 | /** |
||
69 | * Get all attachments for the given message. |
||
70 | * |
||
71 | * @param \Swift_Mime_Message $message |
||
72 | * |
||
73 | * @return array |
||
74 | */ |
||
75 | 2 | protected function getAttachments(Swift_Mime_Message $message) |
|
91 | |||
92 | /** |
||
93 | * Format the contacts for the API request |
||
94 | * |
||
95 | * @param array $contacts |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | 3 | protected function getContacts($contacts) |
|
108 | |||
109 | /** |
||
110 | * Get the "From" payload field for the API request. |
||
111 | * |
||
112 | * @param \Swift_Mime_Message $message |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | 3 | protected function getFrom(Swift_Mime_Message $message) |
|
125 | |||
126 | /** |
||
127 | * Get the HTTP payload for sending the Postmark message. |
||
128 | * |
||
129 | * @param \Swift_Mime_Message $message |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | 2 | protected function payload(Swift_Mime_Message $message) |
|
161 | } |
||
162 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: