ArrayTransport.php
TLDR
This file contains the implementation of the ArrayTransport
class, which is responsible for sending email messages using an array as the transport mechanism. It provides methods to send messages, retrieve the collection of messages, clear the messages, and get the string representation of the transport.
Methods
send
This method is responsible for sending a raw message using the array transport. It accepts a RawMessage
object as the message to be sent and an optional Envelope
object. It returns a SentMessage
object representing the sent message.
messages
This method retrieves the collection of messages that have been sent using the array transport.
flush
This method clears all of the messages from the local collection.
Classes
ArrayTransport
The ArrayTransport
class implements the TransportInterface
interface and represents the transport mechanism for sending email messages using an array. It maintains a collection of messages and provides methods to send messages, retrieve the collection of messages, clear the messages, and get the string representation of the transport.
<?php
namespace Illuminate\Mail\Transport;
use Illuminate\Support\Collection;
use Stringable;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mime\RawMessage;
class ArrayTransport implements Stringable, TransportInterface
{
/**
* The collection of Symfony 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(RawMessage $message, Envelope $envelope = null): ?SentMessage
{
return $this->messages[] = new SentMessage($message, $envelope ?? Envelope::create($message));
}
/**
* Retrieve the collection of messages.
*
* @return \Illuminate\Support\Collection
*/
public function messages()
{
return $this->messages;
}
/**
* Clear all of the messages from the local collection.
*
* @return \Illuminate\Support\Collection
*/
public function flush()
{
return $this->messages = new Collection;
}
/**
* Get the string representation of the transport.
*
* @return string
*/
public function __toString(): string
{
return 'array';
}
}