/**
* Sends messages using the given transport instance.
*
* @param Swift_Transport $transport A transport instance
* @param string[] &$failedRecipients An array of failures by-reference
*
* @return int The number of sent emails
*/
public function flushQueue(Swift_Transport $transport, &$failedRecipients = null)
{
if (!$transport->isStarted()) {
$transport->start();
}
$failedRecipients = (array) $failedRecipients;
$count = 0;
$time = time();
foreach (new DirectoryIterator($this->_path) as $file) {
$file = $file->getRealPath();
if (!strpos($file, '.message')) {
continue;
}
$message = unserialize(file_get_contents($file));
$count += $transport->send($message, $failedRecipients);
unlink($file);
if ($this->getMessageLimit() && $count >= $this->getMessageLimit()) {
break;
}
if ($this->getTimeLimit() && time() - $time >= $this->getTimeLimit()) {
break;
}
}
return $count;
}