|
4 | 4 |
|
5 | 5 | use Illuminate\Support\Arr; |
6 | 6 | use Illuminate\Support\Str; |
7 | | -use Swift_Mailer; |
8 | 7 |
|
9 | 8 | trait CreatesMailers |
10 | 9 | { |
11 | | - protected function createLaravel8Mailer($app) |
12 | | - { |
13 | | - $defaultDriver = $app['mail.manager']->getDefaultDriver(); |
14 | | - $config = $this->getConfig($defaultDriver); |
15 | | - |
16 | | - $swiftMailer = new Swift_Mailer($app['mail.manager']->createTransport($config)); |
17 | | - |
18 | | - // Once we have create the mailer instance, we will set a container instance |
19 | | - // on the mailer. This allows us to resolve mailer classes via containers |
20 | | - // for maximum testability on said classes instead of passing Closures. |
21 | | - $mailer = new Laravel8Mailer( |
22 | | - 'smtp', |
23 | | - $app['view'], |
24 | | - $swiftMailer, |
25 | | - $app['events'] |
26 | | - ); |
27 | | - |
28 | | - if ($app->bound('queue')) { |
29 | | - $mailer->setQueue($app['queue']); |
30 | | - } |
31 | | - |
32 | | - // Next we will set all of the global addresses on this mailer, which allows |
33 | | - // for easy unification of all "from" addresses as well as easy debugging |
34 | | - // of sent messages since they get be sent into a single email address. |
35 | | - foreach (['from', 'reply_to', 'to', 'return_path'] as $type) { |
36 | | - $this->setGlobalAddress($mailer, $config, $type); |
37 | | - } |
38 | 10 |
|
39 | | - return $mailer; |
40 | | - } |
41 | | - |
42 | | - protected function createLaravel9Mailer($app) |
| 11 | + protected function createGeneralLaravelMailer($app) |
43 | 12 | { |
44 | 13 | $defaultDriver = $app['mail.manager']->getDefaultDriver(); |
45 | 14 | $config = $this->getConfig($defaultDriver); |
46 | 15 |
|
47 | | - // We get Symfony Transport from Laravel 9 mailer |
48 | | - if (version_compare(app()->version(), '10.0.0', '<')) { |
49 | | - $symfonyTransport = $app['mail.manager']->getSymfonyTransport(); |
50 | | - } else { |
51 | | - $symfonyTransport = $app['mailer']->getSymfonyTransport(); |
52 | | - } |
| 16 | + // We get Symfony Transport from Laravel 10+ mailer |
| 17 | + $symfonyTransport = $app['mailer']->getSymfonyTransport(); |
53 | 18 |
|
54 | 19 | // Once we have create the mailer instance, we will set a container instance |
55 | 20 | // on the mailer. This allows us to resolve mailer classes via containers |
56 | 21 | // for maximum testability on said classes instead of passing Closures. |
57 | | - $mailer = new Laravel9Mailer( |
| 22 | + $mailer = new GeneralLaravelMailer( |
58 | 23 | 'smtp', |
59 | 24 | $app['view'], |
60 | 25 | $symfonyTransport, |
@@ -93,11 +58,7 @@ protected function getConfig($name = 'smtp') |
93 | 58 | */ |
94 | 59 | protected function setGlobalAddress($mailer, array $config, $type) |
95 | 60 | { |
96 | | - if (version_compare(app()->version(), '7.0.0', '<')) { |
97 | | - $address = Arr::get($config, $type); |
98 | | - } else { |
99 | | - $address = Arr::get($config, $type, $this->app['config']['mail.'.$type]); |
100 | | - } |
| 61 | + $address = Arr::get($config, $type, $this->app['config']['mail.'.$type]); |
101 | 62 |
|
102 | 63 | if (is_array($address) && isset($address['address'])) { |
103 | 64 | $mailer->{'always'.Str::studly($type)}($address['address'], $address['name']); |
|
0 commit comments