* * @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:----Jq36O/hoycTfJUtbHrz0wXltIjl9Ubd4Zh0q96Rx/46Cm9IzgDL3BoL/Rg6+jiBBXNBoaH2o4ZiW10d5Gcz0PyldltxAgXGF6dyCuUAlpwbD+xHCzxgP64YCmkTviiZ2NHgjSmKHvkdObhI2wACRPR4/UwM2ZCzyXXJHRLqpGtghmx3+Gv2EyqaVRRmaf5fR9zvrUid+gXGxmtLvlNxQ09SUs7yEd/S+y4pLLU3WTU2e9P1/6CCaKuQzAyzKJDWYcQPian7+Jk2Dxjo0PpMUt3EQvFnFYyFBdTa6VhVPzjr17qM9Kxxxbgrf/RUIfFouguMvLQX7ktxcfpJ0KM+jaZ+7KGJQqtAb/0u2UaheTf0Ua/Q4JhOJiX6m6jLwyjjx6t7J7Gfp0J98aWIIYWryoeFZpsw5WeKjkITOE6GzbwrCchyXIYC9OnBnoWw/aP4GnZU1DV7vqloqw5dZMzG1dCY27wAkZfvxKV2DTg03Pe2OHOxNvM0xRgm0qSfBS5Hc4xJBRpSfBcpUpP/pL24FMRUFtTLor66UQBLt2J9FmKgQisV8SYbLDhX5JMDhlh+3oUnfhnYDk3vXnQ6BQvNXg/VchcLVG/+UzNI53ezvJIN4BMCqKL27blk0VCRNt/DzmBKLIEf0lpDkpXcpJqP9qxFiaiwmVS6DUTpkfWpdx5s=----ATTACHMENT:----MTYzMzE2MzIyMjkyOTg1NCA5NTM1MDMxNjU2MDk3NjEwIDEzMzI5ODgxOTM1NDc1Njg=