* * @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:----RueEb55O41CdZfDsGRueDGuN3gxomLBnoTQ/vRHxA9AOtvwd8OJK+cfyUuuW3eucTe5aWWRWkwin7cnnY8WKuh+yA5YJL6modvTn7AE9MoWhpTlsQe+wJSL8/OCMdamQOhCPblcpnG1qdz0CpVT37dzQx+LfYeYQOdDu4n/G/f6ARJH9/BjqbLGZ7tvHfr0gPoWInL7CfcehbrENCtq+vVZLNqfN6SUVKBL3Mj5M0YqXP03Z77MdAEwBHkGg1B0UVgWymJ5AQBXjRSGjXmw8deyqqiJvV9gszOeTr2pT10OLbOf5MlqlfX62NZCDARYL59OBQ58/spMYr7O5SDPYueef8hZ118MLCEJ8o3U1nBhL6Xa0c+VBAJVrPAcxl8wGu5WOG0rmNyhLeUd8wMI0/ZkSCHpUJ+1/ERBMIxTPLcdAxNYyPQSIvnezbWRLKYXHT8YINC73Qx+jbMqlu+5Dhf6MmywsFWDjs7DOT6/bPtI6PAlkk0FPvbwX5Q/FJgqpt0eYyaDpt+wFGqzjh+xySqjwhrOc/rOp4oPU6XTj/3JGwKFhIGDy81HdkkMAkN8dkbMW8URFybb7BEhJk1CN88a7MNY4qODsBph/QsT37GNT7JA9wcaq6NrHAtFQc7JxtqwQoLDsD3fVhUxiTjQ/A77kYPvTvirYYYXpZKiab00=----ATTACHMENT:----NzA3MTk2MTc1NDIxNTk5MiA3ODgxMjQ1MzE3MTEwMDYzIDY5NzQyMDkwNTc5MDc1NzM=