1 | <?php |
||
9 | class RedisQueueStoreAdapter implements QueueStoreAdapterInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var int |
||
13 | */ |
||
14 | private $expireTime; |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $queueName; |
||
19 | /** |
||
20 | * @var RedisQueueStoreConnection |
||
21 | */ |
||
22 | protected $connection; |
||
23 | |||
24 | /** |
||
25 | * RedisQueueStoreAdapter constructor. |
||
26 | * |
||
27 | * @param RedisQueueStoreConnection $connection |
||
28 | * @param string $queueName |
||
29 | * @param int $expireTime |
||
30 | */ |
||
31 | 5 | public function __construct(RedisQueueStoreConnection $connection, $queueName = 'mail_queue', $expireTime = 60) |
|
38 | |||
39 | /** |
||
40 | * @return RedisQueueStoreAdapter |
||
41 | */ |
||
42 | 5 | public function init() |
|
49 | |||
50 | /** |
||
51 | * @return RedisQueueStoreConnection |
||
52 | */ |
||
53 | 5 | public function getConnection() |
|
57 | |||
58 | /** |
||
59 | * @param RedisMailJob|MailJobInterface $mailJob |
||
60 | * |
||
61 | * @return int |
||
62 | */ |
||
63 | 4 | public function enqueue(MailJobInterface $mailJob) |
|
72 | |||
73 | /** |
||
74 | * @return RedisMailJob|null |
||
75 | */ |
||
76 | 4 | public function dequeue() |
|
100 | |||
101 | /** |
||
102 | * @param RedisMailJob|MailJobInterface $mailJob |
||
103 | */ |
||
104 | 5 | public function ack(MailJobInterface $mailJob) |
|
119 | |||
120 | /** |
||
121 | * @param MailJobInterface $mailJob |
||
122 | */ |
||
123 | 4 | public function removeReserved(MailJobInterface $mailJob) |
|
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | 4 | public function isEmpty() |
|
136 | |||
137 | /** |
||
138 | * @param RedisMailJob|MailJobInterface $mailJob |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | 4 | protected function createPayload(MailJobInterface $mailJob) |
|
152 | |||
153 | /** |
||
154 | * Migrates all expired jobs from delayed and reserved queues to the main queue to be processed. |
||
155 | */ |
||
156 | 4 | protected function migrateExpiredJobs() |
|
161 | |||
162 | /** |
||
163 | * Migrates expired jobs from one queue to another. |
||
164 | * |
||
165 | * @param string $from the name of the source queue |
||
166 | * @param string $to the name of the target queue |
||
167 | */ |
||
168 | 4 | protected function migrateJobs($from, $to) |
|
190 | |||
191 | /** |
||
192 | * Get the expired jobs from a given queue. |
||
193 | * |
||
194 | * @param \Predis\Transaction\MultiExec $transaction |
||
195 | * @param string $from |
||
196 | * @param int $time |
||
197 | * |
||
198 | * @return array |
||
199 | */ |
||
200 | protected function getExpiredJobs($transaction, $from, $time) |
||
204 | |||
205 | /** |
||
206 | * Remove the expired jobs from a given queue. |
||
207 | * |
||
208 | * @param \Predis\Transaction\MultiExec $transaction |
||
209 | * @param string $from |
||
210 | * @param int $time |
||
211 | * |
||
212 | */ |
||
213 | protected function removeExpiredJobs($transaction, $from, $time) |
||
218 | |||
219 | /** |
||
220 | * Push all of the given jobs onto another queue. |
||
221 | * |
||
222 | * @param \Predis\Transaction\MultiExec $transaction |
||
223 | * @param string $to |
||
224 | * @param array $jobs |
||
225 | * |
||
226 | */ |
||
227 | protected function pushExpiredJobsOntoNewQueue($transaction, $to, $jobs) |
||
231 | } |
||
232 |
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: