summaryrefslogtreecommitdiff
path: root/src/Mail/Transport/LogTransport.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-05 13:40:03 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-05 13:44:43 +0200
commit01e9c22695a3e495f07ab445750221af72e09fe4 (patch)
tree63c01a396d289f5f1e4d11259654e772300ff98c /src/Mail/Transport/LogTransport.php
parent9d34f371cb9c5ab0d60bd3158678b9cc9da6cc80 (diff)
Implemented mailing abstraction
Closes #434
Diffstat (limited to 'src/Mail/Transport/LogTransport.php')
-rw-r--r--src/Mail/Transport/LogTransport.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Mail/Transport/LogTransport.php b/src/Mail/Transport/LogTransport.php
new file mode 100644
index 00000000..6e351302
--- /dev/null
+++ b/src/Mail/Transport/LogTransport.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Engelsystem\Mail\Transport;
+
+use Psr\Log\LoggerInterface;
+use Swift_Mime_SimpleMessage as SimpleMessage;
+
+class LogTransport extends Transport
+{
+ /** @var LoggerInterface */
+ protected $logger;
+
+ public function __construct(LoggerInterface $logger)
+ {
+ $this->logger = $logger;
+ }
+
+ /**
+ * Send the given Message.
+ *
+ * Recipient/sender data will be retrieved from the Message API.
+ * The return value is the number of recipients
+ *
+ * @param SimpleMessage $message
+ * @param string[] $failedRecipients An array of failures by-reference
+ *
+ * @return int
+ */
+ public function send(
+ SimpleMessage $message,
+ &$failedRecipients = null
+ ): int {
+ $this->logger->debug(
+ 'Mail: Send mail "{title}" to "{recipients}":' . PHP_EOL . '{content}',
+ [
+ 'title' => $message->getSubject(),
+ 'recipients' => $this->getTo($message),
+ 'content' => (string)$message->getHeaders() . PHP_EOL . PHP_EOL . $message->toString(),
+ ]
+ );
+
+ return count($this->allRecipients($message));
+ }
+}