From 4993a2901353a0b1678d2b015945304ae2a5a2d3 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Thu, 4 Aug 2016 22:48:44 +0200 Subject: [PATCH] Cleanup. --- lib/Frs/Output/MailOutput.php | 6 ++--- lib/Frs/Output/Transport/GmailTransport.php | 26 ++++++++++--------- lib/Frs/Output/Transport/MailTransport.php | 23 ++++++++++------ lib/Frs/Output/Transport/StdoutTransport.php | 4 +++ .../Output/Transport/TransportInterface.php | 2 ++ 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/lib/Frs/Output/MailOutput.php b/lib/Frs/Output/MailOutput.php index 7f81c11..6ab8816 100644 --- a/lib/Frs/Output/MailOutput.php +++ b/lib/Frs/Output/MailOutput.php @@ -84,9 +84,9 @@ class MailOutput extends GenericOutput $this->setHeadersFromString($headers); $recipients = implode(', ', $this->recipients); // TODO: Check if any recipients in the first place - $this->transport->setRecipients($recipients); - $this->transport->setSubject($this->subject); - $this->transport->setHeaders($this->headers); + $this->transport->setParam('to', $recipients); + $this->transport->setParam('subject', $this->subject); + $this->transport->setParam('headers', $this->headers); $this->transport->setContent($mailbody); return $this->transport->transmit(); } diff --git a/lib/Frs/Output/Transport/GmailTransport.php b/lib/Frs/Output/Transport/GmailTransport.php index f732dfb..e71da57 100644 --- a/lib/Frs/Output/Transport/GmailTransport.php +++ b/lib/Frs/Output/Transport/GmailTransport.php @@ -20,19 +20,21 @@ class GmailTransport implements TransportInterface $this->content = $content; } - public function setRecipients($recipients) + public function setParam($key, $value) { - $this->recipients = $recipients; - } + switch ($key) { + case 'to': + $this->recipients = $value; + break; - public function setSubject($subject) - { - $this->subject = $subject; - } + case 'subject': + $this->subject = $value; + break; - public function setHeaders($headers) - { - $this->headers = $headers; + case 'headers': + $this->headers = $value; + break; + } } /** @@ -42,7 +44,7 @@ class GmailTransport implements TransportInterface * @param string $data Date to encode * @return string Encoded data */ - private function b64url_encode($data) + private function base64UrlEncode($data) { return rtrim(strtr(base64_encode($data), '+/', '-_'), '='); } @@ -57,7 +59,7 @@ class GmailTransport implements TransportInterface $mime->setSubject($this->subject); $message_body = $mime->getMessage(null, null, $this->headers); - $encoded_message = $this->b64url_encode($message_body); + $encoded_message = $this->base64UrlEncode($message_body); $postBody = new \Google_Service_Gmail_Message(); $postBody->setRaw($encoded_message); diff --git a/lib/Frs/Output/Transport/MailTransport.php b/lib/Frs/Output/Transport/MailTransport.php index 794a1c1..ccb0a7a 100644 --- a/lib/Frs/Output/Transport/MailTransport.php +++ b/lib/Frs/Output/Transport/MailTransport.php @@ -14,17 +14,24 @@ class MailTransport implements TransportInterface $this->content = $content; } - public function setRecipients($recipients) + public function setParam($key, $value) { - $this->recipients = $recipients; + switch ($key) { + case 'to': + $this->recipients = $value; + break; + + case 'subject': + $this->subject = $value; + break; + + case 'headers': + $this->setHeaders($value); + break; + } } - public function setSubject($subject) - { - $this->subject = $subject; - } - - public function setHeaders($headers) + private function setHeaders($headers) { $this->headers = ''; foreach ($headers as $key=>$value) { diff --git a/lib/Frs/Output/Transport/StdoutTransport.php b/lib/Frs/Output/Transport/StdoutTransport.php index 373ef50..697568a 100644 --- a/lib/Frs/Output/Transport/StdoutTransport.php +++ b/lib/Frs/Output/Transport/StdoutTransport.php @@ -6,6 +6,10 @@ class StdoutTransport implements TransportInterface { private $content; + public function setParam($key, $value) + { + } + public function setContent($content) { $this->content = $content; diff --git a/lib/Frs/Output/Transport/TransportInterface.php b/lib/Frs/Output/Transport/TransportInterface.php index b210593..e1f441e 100644 --- a/lib/Frs/Output/Transport/TransportInterface.php +++ b/lib/Frs/Output/Transport/TransportInterface.php @@ -4,6 +4,8 @@ namespace Frs\Output\Transport; interface TransportInterface { + public function setParam($key, $value); + public function setContent($content); public function transmit();