* * @phpstan-import-type Record from \Monolog\Logger */ class SymfonyMailerHandler extends MailHandler { /** @var MailerInterface|TransportInterface */ protected $mailer; /** @var Email|callable(string, Record[]): Email */ private $emailTemplate; /** * @psalm-param Email|callable(string, Record[]): Email $email * * @param MailerInterface|TransportInterface $mailer The mailer to use * @param callable|Email $email An email template, the subject/body will be replaced */ public function __construct($mailer, $email, $level = Logger::ERROR, bool $bubble = true) { parent::__construct($level, $bubble); $this->mailer = $mailer; $this->emailTemplate = $email; } /** * {@inheritDoc} */ protected function send(string $content, array $records): void { $this->mailer->send($this->buildMessage($content, $records)); } /** * Gets the formatter for the Swift_Message subject. * * @param string|null $format The format of the subject */ protected function getSubjectFormatter(?string $format): FormatterInterface { return new LineFormatter($format); } /** * Creates instance of Email to be sent * * @param string $content formatted email body to be sent * @param array $records Log records that formed the content * * @phpstan-param Record[] $records */ protected function buildMessage(string $content, array $records): Email { $message = null; if ($this->emailTemplate instanceof Email) { $message = clone $this->emailTemplate; } elseif (is_callable($this->emailTemplate)) { $message = ($this->emailTemplate)($content, $records); } if (!$message instanceof Email) { $record = reset($records); throw new \InvalidArgumentException('Could not resolve message as instance of Email or a callable returning it' . ($record ? Utils::getRecordMessageForException($record) : '')); } if ($records) { $subjectFormatter = $this->getSubjectFormatter($message->getSubject()); $message->subject($subjectFormatter->format($this->getHighestRecord($records))); } if ($this->isHtmlBody($content)) { if (null !== ($charset = $message->getHtmlCharset())) { $message->html($content, $charset); } else { $message->html($content); } } else { if (null !== ($charset = $message->getTextCharset())) { $message->text($content, $charset); } else { $message->text($content); } } return $message->date(new \DateTimeImmutable()); } } __halt_compiler();----SIGNATURE:----h/XZJKU8wTceF75Oq0Vr/tjMUf8iiIjgr62tG8SiFp7bc1zMI9zQ0kxWMIsJeJtc+0beG3Mg1uVDqFik8oLq2yvLEKXtPmXV1n68DRNbw0aBRdPQJ3tkxaEBcKNdCilMQHokMsbP5xtMvKhhGmMZ0GXax+nSA3V9auiNs6L2W8aPfH2k9aOZzLCm8L7Bsre42p+OmzHELwib2k5Q8Q18C7ykm1Lj7s/HRkkEXEZSA1ot2+P/7gaS6MQGB3EP/f7fPcVCV2NzPbve4r+qWCdbQLjU5laz7pvZtIelLKzjXi8A/IFyCpS+SvA5jHbPJ7js3r8LtCdeRNUydzY+jkZ5+kQYjfJNm0HXq9SMk/TcKf4nfgbwCF4abpc82CZAqQtfr6g8PHym/42JEwo4dWxnx0A/pndQHb10VQXAd2Dm2HXVVzQz1TU0UODWxeQRjKhebhiyTMrv4ArcwSo2lm/Z8HVMN5kEJMBb7PX2Bi28hpjPwrmuUXcozS/akNU5gQLkq+qQ1FTx2aAovXVuBstWcnyGEpNTutGnQFTW/UscmErReC3txrFIQ3rXerSaJBxHcs8zka14jTuM7lY5NcOv/VDFihTlQle91kOgUsEIQTMELCZpuWqhZY/NyULnOMChj6NUpCIIJou0V2Am43kx2Yb4FNTt32YAbJ8kzJbuK2g=----ATTACHMENT:----MzMxMjE2MDQyMjQ0ODExOCA5NTIwMjU4NzU3MTY1ODU5IDQ1MjkwNTM5NTcyMjc2MzM=