📂 File Browser

AgentAI/vendor/monolog/monolog/src/Monolog/Handler
🌙 Dark Mode
🎯 Quick Launch:

📁 Directories

📁 Curl/ 🔓 Open
📁 FingersCrossed/ 🔓 Open
📁 Slack/ 🔓 Open
📁 SyslogUdp/ 🔓 Open

📄 Files

🐘 AbstractHandler.php
▶ Open 📄 View Source
🐘 AbstractProcessingHandler.php
▶ Open 📄 View Source
🐘 AbstractSyslogHandler.php
▶ Open 📄 View Source
🐘 AmqpHandler.php
▶ Open 📄 View Source
🐘 BrowserConsoleHandler.php
▶ Open 📄 View Source
🐘 BufferHandler.php
▶ Open 📄 View Source
🐘 ChromePHPHandler.php
▶ Open 📄 View Source
🐘 CouchDBHandler.php
▶ Open 📄 View Source
🐘 CubeHandler.php
▶ Open 📄 View Source
🐘 DeduplicationHandler.php
▶ Open 📄 View Source
🐘 DoctrineCouchDBHandler.php
▶ Open 📄 View Source
🐘 DynamoDbHandler.php
▶ Open 📄 View Source
🐘 ElasticaHandler.php
▶ Open 📄 View Source
🐘 ElasticsearchHandler.php
▶ Open 📄 View Source
🐘 ErrorLogHandler.php
▶ Open 📄 View Source
🐘 FallbackGroupHandler.php
▶ Open 📄 View Source
🐘 FilterHandler.php
▶ Open 📄 View Source
🐘 FingersCrossedHandler.php
▶ Open 📄 View Source
🐘 FirePHPHandler.php
▶ Open 📄 View Source
🐘 FleepHookHandler.php
▶ Open 📄 View Source
🐘 FlowdockHandler.php
▶ Open 📄 View Source
🐘 FormattableHandlerInterface.php
▶ Open 📄 View Source
🐘 FormattableHandlerTrait.php
▶ Open 📄 View Source
🐘 GelfHandler.php
▶ Open 📄 View Source
🐘 GroupHandler.php
▶ Open 📄 View Source
🐘 Handler.php
▶ Open 📄 View Source
🐘 HandlerInterface.php
▶ Open 📄 View Source
🐘 HandlerWrapper.php
▶ Open 📄 View Source
🐘 IFTTTHandler.php
▶ Open 📄 View Source
🐘 InsightOpsHandler.php
▶ Open 📄 View Source
🐘 LogEntriesHandler.php
▶ Open 📄 View Source
🐘 LogglyHandler.php
▶ Open 📄 View Source
🐘 LogmaticHandler.php
▶ Open 📄 View Source
🐘 MailHandler.php
▶ Open 📄 View Source
🐘 MandrillHandler.php
▶ Open 📄 View Source
🐘 MissingExtensionException.php
▶ Open 📄 View Source
🐘 MongoDBHandler.php
▶ Open 📄 View Source
🐘 NativeMailerHandler.php
▶ Open 📄 View Source
🐘 NewRelicHandler.php
▶ Open 📄 View Source
🐘 NoopHandler.php
▶ Open 📄 View Source
🐘 NullHandler.php
▶ Open 📄 View Source
🐘 OverflowHandler.php
▶ Open 📄 View Source
🐘 PHPConsoleHandler.php
▶ Open 📄 View Source
🐘 ProcessHandler.php
▶ Open 📄 View Source
🐘 ProcessableHandlerInterface.php
▶ Open 📄 View Source
🐘 ProcessableHandlerTrait.php
▶ Open 📄 View Source
🐘 PsrHandler.php
▶ Open 📄 View Source
🐘 PushoverHandler.php
▶ Open 📄 View Source
🐘 RedisHandler.php
▶ Open 📄 View Source
🐘 RedisPubSubHandler.php
▶ Open 📄 View Source
🐘 RollbarHandler.php
▶ Open 📄 View Source
🐘 RotatingFileHandler.php
▶ Open 📄 View Source
🐘 SamplingHandler.php
▶ Open 📄 View Source
🐘 SendGridHandler.php
▶ Open 📄 View Source
🐘 SlackHandler.php
▶ Open 📄 View Source
🐘 SlackWebhookHandler.php
▶ Open 📄 View Source
🐘 SocketHandler.php
▶ Open 📄 View Source
🐘 SqsHandler.php
▶ Open 📄 View Source
🐘 StreamHandler.php
▶ Open 📄 View Source
🐘 SymfonyMailerHandler.php
▶ Open 📄 View Source
🐘 SyslogHandler.php
▶ Open 📄 View Source
🐘 SyslogUdpHandler.php
▶ Open 📄 View Source
🐘 TelegramBotHandler.php
▶ Open 📄 View Source
🐘 TestHandler.php
▶ Open 📄 View Source
🐘 WebRequestRecognizerTrait.php
▶ Open 📄 View Source
🐘 WhatFailureGroupHandler.php
▶ Open 📄 View Source
🐘 ZendMonitorHandler.php
▶ Open 📄 View Source

📄 Source: SymfonyMailerHandler.php

<?php declare(strict_types=1);

/*
 * This file is part of the Monolog package.
 *
 * (c) Jordi Boggiano <j.boggiano@seld.be>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Monolog\Handler;

use Closure;
use Monolog\Level;
use Monolog\LogRecord;
use Monolog\Utils;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mime\Email;

/**
 * SymfonyMailerHandler uses Symfony's Mailer component to send the emails
 *
 * @author Jordi Boggiano <j.boggiano@seld.be>
 */
class SymfonyMailerHandler extends MailHandler
{
    protected MailerInterface|TransportInterface $mailer;
    /** @var Email|Closure(string, LogRecord[]): Email */
    private Email|Closure $emailTemplate;

    /**
     * @phpstan-param Email|Closure(string, LogRecord[]): Email $email
     *
     * @param MailerInterface|TransportInterface $mailer The mailer to use
     * @param Closure|Email                      $email  An email template, the subject/body will be replaced
     */
    public function __construct($mailer, Email|Closure $email, int|string|Level $level = Level::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 LogRecord[] $records Log records that formed the content
     */
    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 instanceof LogRecord ? Utils::getRecordMessageForException($record) : ''));
        }

        if (\count($records) > 0) {
            $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());
    }
}
← Back