diff options
author | Marvin Borner | 2018-05-23 22:23:28 +0200 |
---|---|---|
committer | Marvin Borner | 2018-05-23 22:23:28 +0200 |
commit | b66a61addb6c8e66cb26fcf74b532d68891267e4 (patch) | |
tree | 05e9449ff25bdc98f68105f41923ccb9f6ef5095 /main/app/sprinkles/core/src/Mail | |
parent | 1d4ef435177a5f9b6d1a289800d933e49be0c550 (diff) |
Refactored code, many fixes and improvements in chat backend+frontend
Diffstat (limited to 'main/app/sprinkles/core/src/Mail')
-rw-r--r-- | main/app/sprinkles/core/src/Mail/EmailRecipient.php | 25 | ||||
-rw-r--r-- | main/app/sprinkles/core/src/Mail/MailMessage.php | 49 | ||||
-rw-r--r-- | main/app/sprinkles/core/src/Mail/Mailer.php | 58 | ||||
-rw-r--r-- | main/app/sprinkles/core/src/Mail/StaticMailMessage.php | 16 | ||||
-rw-r--r-- | main/app/sprinkles/core/src/Mail/TwigMailMessage.php | 18 |
5 files changed, 68 insertions, 98 deletions
diff --git a/main/app/sprinkles/core/src/Mail/EmailRecipient.php b/main/app/sprinkles/core/src/Mail/EmailRecipient.php index 0b9381a..33b7db7 100644 --- a/main/app/sprinkles/core/src/Mail/EmailRecipient.php +++ b/main/app/sprinkles/core/src/Mail/EmailRecipient.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Sprinkle\Core\Mail; /** @@ -49,8 +50,7 @@ class EmailRecipient * @param string $name The primary recipient name. * @param array $params An array of template parameters to render the email message with for this particular recipient. */ - public function __construct($email, $name = "", $params = []) - { + public function __construct($email, $name = "", $params = []) { $this->email = $email; $this->name = $name; $this->params = $params; @@ -62,8 +62,7 @@ class EmailRecipient * @param string $email The CC recipient email address. * @param string $name The CC recipient name. */ - public function cc($email, $name = "") - { + public function cc($email, $name = "") { $this->cc[] = [ "email" => $email, "name" => $name @@ -76,8 +75,7 @@ class EmailRecipient * @param string $email The BCC recipient email address. * @param string $name The BCC recipient name. */ - public function bcc($email, $name = "") - { + public function bcc($email, $name = "") { $this->bcc[] = [ "email" => $email, "name" => $name @@ -89,8 +87,7 @@ class EmailRecipient * * @return string the primary recipient email address. */ - public function getEmail() - { + public function getEmail() { return $this->email; } @@ -99,8 +96,7 @@ class EmailRecipient * * @return string the primary recipient name. */ - public function getName() - { + public function getName() { return $this->name; } @@ -109,8 +105,7 @@ class EmailRecipient * * @return array The parameters (name => value) to use when rendering an email template for this recipient. */ - public function getParams() - { + public function getParams() { return $this->params; } @@ -119,8 +114,7 @@ class EmailRecipient * * @return array A list of CCs for this recipient. Each CC is an associative array with `email` and `name` properties. */ - public function getCCs() - { + public function getCCs() { return $this->cc; } @@ -129,8 +123,7 @@ class EmailRecipient * * @return array A list of BCCs for this recipient. Each BCC is an associative array with `email` and `name` properties. */ - public function getBCCs() - { + public function getBCCs() { return $this->bcc; } } diff --git a/main/app/sprinkles/core/src/Mail/MailMessage.php b/main/app/sprinkles/core/src/Mail/MailMessage.php index 29bcf15..6aea56d 100644 --- a/main/app/sprinkles/core/src/Mail/MailMessage.php +++ b/main/app/sprinkles/core/src/Mail/MailMessage.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Sprinkle\Core\Mail; /** @@ -24,7 +25,7 @@ abstract class MailMessage /** * @var string The current sender name. */ - protected $fromName = null; + protected $fromName = NULL; /** * @var EmailRecipient[] A list of recipients for this message. @@ -34,12 +35,12 @@ abstract class MailMessage /** * @var string The current reply-to email. */ - protected $replyEmail = null; + protected $replyEmail = NULL; /** * @var string The current reply-to name. */ - protected $replyName = null; + protected $replyName = NULL; /** * Gets the fully rendered text of the message body. @@ -60,8 +61,7 @@ abstract class MailMessage * * @param EmailRecipient $recipient */ - public function addEmailRecipient(EmailRecipient $recipient) - { + public function addEmailRecipient(EmailRecipient $recipient) { $this->recipients[] = $recipient; return $this; } @@ -69,8 +69,7 @@ abstract class MailMessage /** * Clears out all recipients for this message. */ - public function clearRecipients() - { + public function clearRecipients() { $this->recipients = array(); } @@ -80,12 +79,11 @@ abstract class MailMessage * This is a shortcut for calling setFromEmail, setFromName, setReplyEmail, and setReplyName. * @param string $fromInfo An array containing 'email', 'name', 'reply_email', and 'reply_name'. */ - public function from($fromInfo = []) - { + public function from($fromInfo = []) { $this->setFromEmail(isset($fromInfo['email']) ? $fromInfo['email'] : ""); - $this->setFromName(isset($fromInfo['name']) ? $fromInfo['name'] : null); - $this->setReplyEmail(isset($fromInfo['reply_email']) ? $fromInfo['reply_email'] : null); - $this->setReplyName(isset($fromInfo['reply_name']) ? $fromInfo['reply_name'] : null); + $this->setFromName(isset($fromInfo['name']) ? $fromInfo['name'] : NULL); + $this->setReplyEmail(isset($fromInfo['reply_email']) ? $fromInfo['reply_email'] : NULL); + $this->setReplyName(isset($fromInfo['reply_name']) ? $fromInfo['reply_name'] : NULL); return $this; } @@ -95,8 +93,7 @@ abstract class MailMessage * * @return string */ - public function getFromEmail() - { + public function getFromEmail() { return $this->fromEmail; } @@ -105,8 +102,7 @@ abstract class MailMessage * * @return string */ - public function getFromName() - { + public function getFromName() { return isset($this->fromName) ? $this->fromName : $this->getFromEmail(); } @@ -115,8 +111,7 @@ abstract class MailMessage * * @return EmailRecipient[] */ - public function getRecipients() - { + public function getRecipients() { return $this->recipients; } @@ -125,8 +120,7 @@ abstract class MailMessage * * @return string */ - public function getReplyEmail() - { + public function getReplyEmail() { return isset($this->replyEmail) ? $this->replyEmail : $this->getFromEmail(); } @@ -135,8 +129,7 @@ abstract class MailMessage * * @return string */ - public function getReplyName() - { + public function getReplyName() { return isset($this->replyName) ? $this->replyName : $this->getFromName(); } @@ -145,8 +138,7 @@ abstract class MailMessage * * @param string $fromEmail */ - public function setFromEmail($fromEmail) - { + public function setFromEmail($fromEmail) { $this->fromEmail = $fromEmail; return $this; } @@ -156,8 +148,7 @@ abstract class MailMessage * * @param string $fromName */ - public function setFromName($fromName) - { + public function setFromName($fromName) { $this->fromName = $fromName; return $this; } @@ -167,8 +158,7 @@ abstract class MailMessage * * @param string $replyEmail */ - public function setReplyEmail($replyEmail) - { + public function setReplyEmail($replyEmail) { $this->replyEmail = $replyEmail; return $this; } @@ -178,8 +168,7 @@ abstract class MailMessage * * @param string $replyName */ - public function setReplyName($replyName) - { + public function setReplyName($replyName) { $this->replyName = $replyName; return $this; } diff --git a/main/app/sprinkles/core/src/Mail/Mailer.php b/main/app/sprinkles/core/src/Mail/Mailer.php index 5b346b4..82302b8 100644 --- a/main/app/sprinkles/core/src/Mail/Mailer.php +++ b/main/app/sprinkles/core/src/Mail/Mailer.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Sprinkle\Core\Mail; use Monolog\Logger; @@ -35,12 +36,11 @@ class Mailer * @param mixed[] $config An array of configuration parameters for phpMailer. * @throws \phpmailerException Wrong mailer config value given. */ - public function __construct($logger, $config = []) - { + public function __construct($logger, $config = []) { $this->logger = $logger; // 'true' tells PHPMailer to use exceptions instead of error codes - $this->phpMailer = new \PHPMailer(true); + $this->phpMailer = new \PHPMailer(TRUE); // Configuration options if (isset($config['mailer'])) { @@ -49,14 +49,14 @@ class Mailer } if ($config['mailer'] == 'smtp') { - $this->phpMailer->isSMTP(true); - $this->phpMailer->Host = $config['host']; - $this->phpMailer->Port = $config['port']; - $this->phpMailer->SMTPAuth = $config['auth']; + $this->phpMailer->isSMTP(TRUE); + $this->phpMailer->Host = $config['host']; + $this->phpMailer->Port = $config['port']; + $this->phpMailer->SMTPAuth = $config['auth']; $this->phpMailer->SMTPSecure = $config['secure']; - $this->phpMailer->Username = $config['username']; - $this->phpMailer->Password = $config['password']; - $this->phpMailer->SMTPDebug = $config['smtp_debug']; + $this->phpMailer->Username = $config['username']; + $this->phpMailer->Password = $config['password']; + $this->phpMailer->SMTPDebug = $config['smtp_debug']; if (isset($config['smtp_options'])) { $this->phpMailer->SMTPOptions = $config['smtp_options']; @@ -71,7 +71,7 @@ class Mailer } // Pass logger into phpMailer object - $this->phpMailer->Debugoutput = function($message, $level) { + $this->phpMailer->Debugoutput = function ($message, $level) { $this->logger->debug($message); }; } @@ -81,8 +81,7 @@ class Mailer * * @return \PHPMailer */ - public function getPhpMailer() - { + public function getPhpMailer() { return $this->phpMailer; } @@ -95,8 +94,7 @@ class Mailer * @param bool $clearRecipients Set to true to clear the list of recipients in the message after calling send(). This helps avoid accidentally sending a message multiple times. * @throws \phpmailerException The message could not be sent. */ - public function send(MailMessage $message, $clearRecipients = true) - { + public function send(MailMessage $message, $clearRecipients = TRUE) { $this->phpMailer->From = $message->getFromEmail(); $this->phpMailer->FromName = $message->getFromName(); $this->phpMailer->addReplyTo($message->getReplyEmail(), $message->getReplyName()); @@ -107,20 +105,20 @@ class Mailer // Add any CCs and BCCs if ($recipient->getCCs()) { - foreach($recipient->getCCs() as $cc) { + foreach ($recipient->getCCs() as $cc) { $this->phpMailer->addCC($cc['email'], $cc['name']); } } - + if ($recipient->getBCCs()) { - foreach($recipient->getBCCs() as $bcc) { + foreach ($recipient->getBCCs() as $bcc) { $this->phpMailer->addBCC($bcc['email'], $bcc['name']); } } } $this->phpMailer->Subject = $message->renderSubject(); - $this->phpMailer->Body = $message->renderBody(); + $this->phpMailer->Body = $message->renderBody(); // Try to send the mail. Will throw an exception on failure. $this->phpMailer->send(); @@ -136,15 +134,14 @@ class Mailer } /** - * Send a MailMessage message, sending a separate email to each recipient. + * Send a MailMessage message, sending a separate email to each recipient. * * If the message object supports message templates, this will render the template with the corresponding placeholder values for each recipient. * @param MailMessage $message * @param bool $clearRecipients Set to true to clear the list of recipients in the message after calling send(). This helps avoid accidentally sending a message multiple times. * @throws \phpmailerException The message could not be sent. */ - public function sendDistinct(MailMessage $message, $clearRecipients = true) - { + public function sendDistinct(MailMessage $message, $clearRecipients = TRUE) { $this->phpMailer->From = $message->getFromEmail(); $this->phpMailer->FromName = $message->getFromName(); $this->phpMailer->addReplyTo($message->getReplyEmail(), $message->getReplyName()); @@ -155,23 +152,23 @@ class Mailer // Add any CCs and BCCs if ($recipient->getCCs()) { - foreach($recipient->getCCs() as $cc) { + foreach ($recipient->getCCs() as $cc) { $this->phpMailer->addCC($cc['email'], $cc['name']); } } - + if ($recipient->getBCCs()) { - foreach($recipient->getBCCs() as $bcc) { + foreach ($recipient->getBCCs() as $bcc) { $this->phpMailer->addBCC($bcc['email'], $bcc['name']); } } - + $this->phpMailer->Subject = $message->renderSubject($recipient->getParams()); - $this->phpMailer->Body = $message->renderBody($recipient->getParams()); - + $this->phpMailer->Body = $message->renderBody($recipient->getParams()); + // Try to send the mail. Will throw an exception on failure. $this->phpMailer->send(); - + // Clear recipients from the PHPMailer object for this iteration, // so that we can send a separate email to the next recipient. $this->phpMailer->clearAllRecipients(); @@ -189,8 +186,7 @@ class Mailer * @param mixed[] $options * @return Mailer */ - public function setOptions($options) - { + public function setOptions($options) { if (isset($options['isHtml'])) { $this->phpMailer->isHTML($options['isHtml']); } diff --git a/main/app/sprinkles/core/src/Mail/StaticMailMessage.php b/main/app/sprinkles/core/src/Mail/StaticMailMessage.php index 098bbfc..482226c 100644 --- a/main/app/sprinkles/core/src/Mail/StaticMailMessage.php +++ b/main/app/sprinkles/core/src/Mail/StaticMailMessage.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Sprinkle\Core\Mail; /** @@ -32,8 +33,7 @@ class StaticMailMessage extends MailMessage * @param string $subject * @param string $body */ - public function __construct($subject = "", $body = "") - { + public function __construct($subject = "", $body = "") { $this->subject = $subject; $this->body = $body; } @@ -41,16 +41,14 @@ class StaticMailMessage extends MailMessage /** * {@inheritDoc} */ - public function renderBody($params = []) - { + public function renderBody($params = []) { return $this->body; } /** * {@inheritDoc} */ - public function renderSubject($params = []) - { + public function renderSubject($params = []) { return $this->subject; } @@ -59,8 +57,7 @@ class StaticMailMessage extends MailMessage * * @param string $subject */ - public function setSubject($subject) - { + public function setSubject($subject) { $this->subject = $subject; return $this; } @@ -70,8 +67,7 @@ class StaticMailMessage extends MailMessage * * @param string $body */ - public function setBody($body) - { + public function setBody($body) { $this->body = $body; return $this; } diff --git a/main/app/sprinkles/core/src/Mail/TwigMailMessage.php b/main/app/sprinkles/core/src/Mail/TwigMailMessage.php index aa65240..e20b906 100644 --- a/main/app/sprinkles/core/src/Mail/TwigMailMessage.php +++ b/main/app/sprinkles/core/src/Mail/TwigMailMessage.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Sprinkle\Core\Mail; /** @@ -37,8 +38,7 @@ class TwigMailMessage extends MailMessage * @param Slim\Views\Twig $view The Twig view object used to render mail templates. * @param string $filename optional Set the Twig template to use for this message. */ - public function __construct($view, $filename = null) - { + public function __construct($view, $filename = NULL) { $this->view = $view; $twig = $this->view->getEnvironment(); @@ -46,7 +46,7 @@ class TwigMailMessage extends MailMessage // TODO: should we keep this separate from the local parameters? $this->params = $twig->getGlobals(); - if ($filename !== null) { + if ($filename !== NULL) { $this->template = $twig->loadTemplate($filename); } } @@ -56,8 +56,7 @@ class TwigMailMessage extends MailMessage * * @param mixed[] $params */ - public function addParams($params = []) - { + public function addParams($params = []) { $this->params = array_replace_recursive($this->params, $params); return $this; } @@ -65,8 +64,7 @@ class TwigMailMessage extends MailMessage /** * {@inheritDoc} */ - public function renderSubject($params = []) - { + public function renderSubject($params = []) { $params = array_replace_recursive($this->params, $params); return $this->template->renderBlock('subject', $params); } @@ -74,8 +72,7 @@ class TwigMailMessage extends MailMessage /** * {@inheritDoc} */ - public function renderBody($params = []) - { + public function renderBody($params = []) { $params = array_replace_recursive($this->params, $params); return $this->template->renderBlock('body', $params); } @@ -85,8 +82,7 @@ class TwigMailMessage extends MailMessage * * @param Twig_Template $template The Twig template object, to source the content for this message. */ - public function setTemplate($template) - { + public function setTemplate($template) { $this->template = $template; return $this; } |