Skip to content

Commit

Permalink
Add array transport in order to store Swift messages in memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
sileence committed Dec 21, 2016
1 parent 40b0217 commit 6a905c7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/Illuminate/Mail/Transport/ArrayTransport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Illuminate\Mail\Transport;

use Swift_Mime_Message;
use Illuminate\Support\Collection;

class ArrayTransport extends Transport
{
/**
* The collection of Swift Messages.
*
* @var \Illuminate\Support\Collection
*/
protected $messages;

/**
* Create a new array transport instance.
*
* @return void
*/
public function __construct()
{
$this->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;
}
}
9 changes: 9 additions & 0 deletions src/Illuminate/Mail/TransportManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 6a905c7

Please sign in to comment.