0

I have a problem with swift mailer and monolog on Symfony 3.0.2:

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

An extract appDevDebugProjectContainer.php on line 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);
    }

An extract appDevDebugProjectContainer.php on line 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);
    }

Sends him of e-mail with swiftmailer only work.

I already have this configuration with the same environment but symfony 2.7 and that works.

And this configuration works on a wamp (php7) but not on my environement OSX and server Linux ...

Thank you for your help

Romain
  • 1
  • 2

1 Answers1

0

fix with symfony 3.0.3 and monolog 1.18

Romain
  • 1
  • 2