From 90e1a949623ead173c0952f802d7b5c5487251b1 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Fri, 5 Oct 2018 15:35:14 +0200 Subject: Make application name configurable * Added app_name configuration option * Extended `EngelsystemMailer` to prepend the application name to all mails Closes #426 --- src/Mail/EngelsystemMailer.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/Mail/EngelsystemMailer.php') diff --git a/src/Mail/EngelsystemMailer.php b/src/Mail/EngelsystemMailer.php index 17047cc8..81660681 100644 --- a/src/Mail/EngelsystemMailer.php +++ b/src/Mail/EngelsystemMailer.php @@ -10,6 +10,13 @@ class EngelsystemMailer extends Mailer /** @var Renderer|null */ protected $view; + /** @var string */ + protected $subjectPrefix = null; + + /** + * @param SwiftMailer $mailer + * @param Renderer $view + */ public function __construct(SwiftMailer $mailer, Renderer $view = null) { parent::__construct($mailer); @@ -32,4 +39,37 @@ class EngelsystemMailer extends Mailer return $this->send($to, $subject, $body); } + + /** + * Send the mail + * + * @param string|string[] $to + * @param string $subject + * @param string $body + * @return int + */ + public function send($to, string $subject, string $body): int + { + if ($this->subjectPrefix) { + $subject = sprintf('[%s] %s', $this->subjectPrefix, $subject); + } + + return parent::send($to, $subject, $body); + } + + /** + * @return string + */ + public function getSubjectPrefix(): string + { + return $this->subjectPrefix; + } + + /** + * @param string $subjectPrefix + */ + public function setSubjectPrefix(string $subjectPrefix) + { + $this->subjectPrefix = $subjectPrefix; + } } -- cgit v1.2.3-70-g09d2