Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Add array transport in order to store Swift messages in memory #16906

Merged
merged 1 commit into from
Dec 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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