|
2 | 2 |
|
3 | 3 | namespace Mailjet\LaravelMailjet; |
4 | 4 |
|
| 5 | +use Exception; |
5 | 6 | use Illuminate\Mail\MailServiceProvider; |
6 | 7 | use Mailjet\LaravelMailjet\Transport\MailjetTransport; |
| 8 | +use Swift_Events_SimpleEventDispatcher as EventDispatcher; |
7 | 9 |
|
8 | 10 | class MailjetMailServiceProvider extends MailServiceProvider |
9 | 11 | { |
10 | 12 | /** |
11 | | - * Extended register the Swift Transport instance. |
| 13 | + * Extended register the Illuminate Mailer instance. |
12 | 14 | * |
13 | 15 | * @return void |
14 | 16 | */ |
15 | | - protected function registerSwiftTransport() |
| 17 | + protected function registerIlluminateMailer(): void |
16 | 18 | { |
17 | | - parent::registerSwiftTransport(); |
18 | | - app('swift.transport')->extend('mailjet', function ($app) { |
19 | | - $config = $this->app['config']->get('services.mailjet', array()); |
20 | | - $call = $this->app['config']->get('services.mailjet.transactional.call', true); |
21 | | - $options = $this->app['config']->get('services.mailjet.transactional.options', array()); |
| 19 | + parent::registerIlluminateMailer(); |
22 | 20 |
|
23 | | - return new MailjetTransport(new \Swift_Events_SimpleEventDispatcher(), $config['key'], $config['secret'], $call, $options); |
24 | | - }); |
| 21 | + try { |
| 22 | + app('mail.manager')->extend('mailjet', function () { |
| 23 | + return $this->mailjetTransport(); |
| 24 | + }); |
| 25 | + } catch (Exception $e) { |
| 26 | + app('swift.transport')->extend('mailjet', function () { |
| 27 | + return $this->mailjetTransport(); |
| 28 | + }); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Return configured MailjetTransport. |
| 34 | + * |
| 35 | + * @return MailjetTransport |
| 36 | + */ |
| 37 | + protected function mailjetTransport(): MailjetTransport |
| 38 | + { |
| 39 | + $config = $this->app['config']->get('services.mailjet', []); |
| 40 | + $call = $this->app['config']->get('services.mailjet.transactional.call', true); |
| 41 | + $options = $this->app['config']->get('services.mailjet.transactional.options', []); |
| 42 | + |
| 43 | + return new MailjetTransport(new EventDispatcher(), $config['key'], $config['secret'], $call, $options); |
25 | 44 | } |
26 | 45 | } |
0 commit comments