From 6a905c75966debdca6323f5b70ca622f02bdcc95 Mon Sep 17 00:00:00 2001 From: Duilio Palacios Date: Sat, 8 Oct 2016 18:08:39 +0100 Subject: [PATCH] Add array transport in order to store Swift messages in memory. --- .../Mail/Transport/ArrayTransport.php | 53 +++++++++++++++++++ src/Illuminate/Mail/TransportManager.php | 9 ++++ 2 files changed, 62 insertions(+) create mode 100644 src/Illuminate/Mail/Transport/ArrayTransport.php diff --git a/src/Illuminate/Mail/Transport/ArrayTransport.php b/src/Illuminate/Mail/Transport/ArrayTransport.php new file mode 100644 index 000000000000..5c709db117c4 --- /dev/null +++ b/src/Illuminate/Mail/Transport/ArrayTransport.php @@ -0,0 +1,53 @@ +messages = new Collection; + } + + /** + * {@inheritdoc} + */ + public function send(Swift_Mime_Message $message, &$failedRecipients = null) + { + $this->beforeSendPerformed($message); + + $this->messages[] = $message; + + return $this->numberOfRecipients($message); + } + + /** + * Return the collection of messages. + * + * @return \Illuminate\Support\Collection + */ + public function getMessages() + { + return $this->messages; + } + + public function clearMessages() + { + return $this->messages = new Collection; + } +} diff --git a/src/Illuminate/Mail/TransportManager.php b/src/Illuminate/Mail/TransportManager.php index 289ff701f89e..01f008a11f6f 100644 --- a/src/Illuminate/Mail/TransportManager.php +++ b/src/Illuminate/Mail/TransportManager.php @@ -10,6 +10,7 @@ use Swift_SmtpTransport as SmtpTransport; use Illuminate\Mail\Transport\LogTransport; use Illuminate\Mail\Transport\SesTransport; +use Illuminate\Mail\Transport\ArrayTransport; use Illuminate\Mail\Transport\MailgunTransport; use Illuminate\Mail\Transport\MandrillTransport; use Illuminate\Mail\Transport\SparkPostTransport; @@ -150,6 +151,14 @@ protected function createLogDriver() return new LogTransport($this->app->make('Psr\Log\LoggerInterface')); } + /** + * Create an instance of the Array Swift Transport Driver. + */ + protected function createArrayDriver() + { + return new ArrayTransport(); + } + /** * Get a fresh Guzzle HTTP client instance. *