带有 Monolog 和 swift 邮件程序的 Symfony 3 错误

Error Symfony 3 with Monolog & swift mailer

我在 Symfony 3.0.2 上使用 swift 邮件程序和独白有问题:

FatalThrowableError in appDevDebugProjectContainer.php line 4963: Type error: Argument 1 passed to SymfonyBundleMonologBundleSwiftMailerMessageFactory_0000000079e53f2b00000001716bb61a50d0bc982eb9e83148fbcc469ab36a58::__construct() must be an instance of Swift_Mailer, instance of Closure given, called in /Users/Romain/Sites/var/cache/dev/appDevDebugProjectContainer.php on line 4043

# Swiftmailer Configuration config.yml
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }

#Monolog config_prod.yml
monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: critical
            handler:      grouped
        grouped:
            type:    group
            members: [streamed, buffered]
        streamed:
            type:  stream
            path:  "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
        buffered:
            type:    buffer
            handler: swift
        swift:
            type:       swift_mailer
            from_email: no-reply@email.com
            to_email:   email@email.com
            subject:    "Subject"
            level:      debug

摘录 appDevDebugProjectContainer.php 第 4963 行

/**
     * {@inheritDoc}
     */
    public function __construct(\Swift_Mailer $mailer, $fromEmail, $toEmail, $subject, $contentType = null)
    {
        static $reflection;

        if (! $this->valueHolder56d41e956b1f5441039037) {
            $reflection = $reflection ?: new \ReflectionClass('Symfony\Bundle\MonologBundle\SwiftMailer\MessageFactory');
            $this->valueHolder56d41e956b1f5441039037 = $reflection->newInstanceWithoutConstructor();
        \Closure::bind(function (\Symfony\Bundle\MonologBundle\SwiftMailer\MessageFactory $this) {
            unset($this->mailer, $this->fromEmail, $this->toEmail, $this->subject, $this->contentType);
        }, $this, 'Symfony\Bundle\MonologBundle\SwiftMailer\MessageFactory')->__invoke($this);

        }

        $this->valueHolder56d41e956b1f5441039037->__construct($mailer, $fromEmail, $toEmail, $subject, $contentType);
    }

摘录 appDevDebugProjectContainer.php 第 4043 行

/**
     * Gets the 'monolog.handler.swift.mail_message_factory' service.
     *
     * This service is shared.
     * This method always returns the same instance of the service.
     *
     * This service is private.
     * If you want to be able to request this service from the container directly,
     * make it public, otherwise you might end up with broken code.
     *
     * @param bool    $lazyLoad whether to try lazy-loading the service with a proxy
     *
     * @return \Symfony\Bundle\MonologBundle\SwiftMailer\MessageFactory A Symfony\Bundle\MonologBundle\SwiftMailer\MessageFactory instance.
     */
    public function getMonolog_Handler_Swift_MailMessageFactoryService($lazyLoad = true)
    {
        if ($lazyLoad) {

            return $this->services['monolog.handler.swift.mail_message_factory'] = new SymfonyBundleMonologBundleSwiftMailerMessageFactory_0000000057f95edf000000015dd8d44e50d0bc982eb9e83148fbcc469ab36a58(
                function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {
                    $wrappedInstance = $this->getMonolog_Handler_Swift_MailMessageFactoryService(false);

                    $proxy->setProxyInitializer(null);

                    return true;
                }
            );
        }

        return new \Symfony\Bundle\MonologBundle\SwiftMailer\MessageFactory($this->get('swiftmailer.mailer.default'), 'contact@domaine.com', array(0 => 'error@domaine.com'), 'Une erreur critique est survenue', NULL);
    }

仅使用 swiftmailer 发送电子邮件给他。

我已经在相同的环境下进行了此配置,但 symfony 2.7 可以正常工作。

并且此配置适用于 wamp (php7) 但不适用于我的环境 OSX 和服务器 Linux ...

感谢您的帮助

修复 symfony 3.0.3 和 monolog 1.18