Skip to content

Commit

Permalink
Add support for Laravel 7 with backport for Laravel 5.x.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDoctor0 committed Mar 24, 2020
1 parent 44e9160 commit a429e9d
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/MailjetMailServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,44 @@

namespace Mailjet\LaravelMailjet;

use Exception;
use Illuminate\Mail\MailServiceProvider;
use Mailjet\LaravelMailjet\Transport\MailjetTransport;
use Swift_Events_SimpleEventDispatcher as EventDispatcher;

class MailjetMailServiceProvider extends MailServiceProvider
{
/**
* Extended register the Swift Transport instance.
* Extended register the Illuminate Mailer instance.
*
* @return void
*/
protected function registerSwiftTransport(): void
protected function registerIlluminateMailer(): void
{
parent::registerSwiftTransport();
parent::registerIlluminateMailer();

app('swift.transport')->extend('mailjet', function () {
$config = $this->app['config']->get('services.mailjet', []);
$call = $this->app['config']->get('services.mailjet.transactional.call', true);
$options = $this->app['config']->get('services.mailjet.transactional.options', []);
try{
app('mail.manager')->extend('mailjet', function () {
return $this->mailjetTransport();
});
} catch (Exception $e) {
app('swift.transport')->extend('mailjet', function () {
return $this->mailjetTransport();
});
}
}

/**
* Return configured MailjetTransport.
*
* @return \Mailjet\LaravelMailjet\Transport\MailjetTransport
*/
protected function mailjetTransport(): MailjetTransport
{
$config = $this->app['config']->get('services.mailjet', []);
$call = $this->app['config']->get('services.mailjet.transactional.call', true);
$options = $this->app['config']->get('services.mailjet.transactional.options', []);

return new MailjetTransport(new EventDispatcher(), $config['key'], $config['secret'], $call, $options);
});
return new MailjetTransport(new EventDispatcher(), $config['key'], $config['secret'], $call, $options);
}
}

0 comments on commit a429e9d

Please sign in to comment.