|
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 createLaravel6Mailer($app) |
12 | | - { |
13 | | - $config = $this->getConfig(); |
14 | | - |
15 | | - // Once we have create the mailer instance, we will set a container instance |
16 | | - // on the mailer. This allows us to resolve mailer classes via containers |
17 | | - // for maximum testability on said classes instead of passing Closures. |
18 | | - $mailer = new Mailer( |
19 | | - $app['view'], |
20 | | - $app['swift.mailer'], |
21 | | - $app['events'] |
22 | | - ); |
23 | | - |
24 | | - if ($app->bound('queue')) { |
25 | | - $mailer->setQueue($app['queue']); |
26 | | - } |
27 | | - |
28 | | - // Next we will set all of the global addresses on this mailer, which allows |
29 | | - // for easy unification of all "from" addresses as well as easy debugging |
30 | | - // of sent messages since they get be sent into a single email address. |
31 | | - foreach (['from', 'reply_to', 'to'] as $type) { |
32 | | - $this->setGlobalAddress($mailer, $config, $type); |
33 | | - } |
34 | | - |
35 | | - return $mailer; |
36 | | - } |
37 | | - |
38 | | - protected function createLaravel7Mailer($app) |
39 | | - { |
40 | | - $defaultDriver = $app['mail.manager']->getDefaultDriver(); |
41 | | - $config = $this->getConfig($defaultDriver); |
42 | | - |
43 | | - // Laravel 7 no longer bindes the swift.mailer: |
44 | | - $swiftMailer = new Swift_Mailer($app['mail.manager']->createTransport($config)); |
45 | | - |
46 | | - // Once we have create the mailer instance, we will set a container instance |
47 | | - // on the mailer. This allows us to resolve mailer classes via containers |
48 | | - // for maximum testability on said classes instead of passing Closures. |
49 | | - $mailer = new Laravel7Mailer( |
50 | | - 'smtp', |
51 | | - $app['view'], |
52 | | - $swiftMailer, |
53 | | - $app['events'] |
54 | | - ); |
55 | | - |
56 | | - if ($app->bound('queue')) { |
57 | | - $mailer->setQueue($app['queue']); |
58 | | - } |
59 | | - |
60 | | - // Next we will set all of the global addresses on this mailer, which allows |
61 | | - // for easy unification of all "from" addresses as well as easy debugging |
62 | | - // of sent messages since they get be sent into a single email address. |
63 | | - foreach (['from', 'reply_to', 'to', 'return_path'] as $type) { |
64 | | - $this->setGlobalAddress($mailer, $config, $type); |
65 | | - } |
66 | | - |
67 | | - return $mailer; |
68 | | - } |
69 | | - |
70 | | - protected function createLaravel8Mailer($app) |
| 10 | + protected function createGeneralLaravelMailer($app) |
71 | 11 | { |
72 | 12 | $defaultDriver = $app['mail.manager']->getDefaultDriver(); |
73 | 13 | $config = $this->getConfig($defaultDriver); |
74 | 14 |
|
75 | | - $swiftMailer = new Swift_Mailer($app['mail.manager']->createTransport($config)); |
| 15 | + // We get Symfony Transport from Laravel 10+ mailer |
| 16 | + $symfonyTransport = $app['mailer']->getSymfonyTransport(); |
76 | 17 |
|
77 | 18 | // Once we have create the mailer instance, we will set a container instance |
78 | 19 | // on the mailer. This allows us to resolve mailer classes via containers |
79 | 20 | // for maximum testability on said classes instead of passing Closures. |
80 | | - $mailer = new Laravel8Mailer( |
81 | | - 'smtp', |
82 | | - $app['view'], |
83 | | - $swiftMailer, |
84 | | - $app['events'] |
85 | | - ); |
86 | | - |
87 | | - if ($app->bound('queue')) { |
88 | | - $mailer->setQueue($app['queue']); |
89 | | - } |
90 | | - |
91 | | - // Next we will set all of the global addresses on this mailer, which allows |
92 | | - // for easy unification of all "from" addresses as well as easy debugging |
93 | | - // of sent messages since they get be sent into a single email address. |
94 | | - foreach (['from', 'reply_to', 'to', 'return_path'] as $type) { |
95 | | - $this->setGlobalAddress($mailer, $config, $type); |
96 | | - } |
97 | | - |
98 | | - return $mailer; |
99 | | - } |
100 | | - |
101 | | - protected function createLaravel9Mailer($app) |
102 | | - { |
103 | | - $defaultDriver = $app['mail.manager']->getDefaultDriver(); |
104 | | - $config = $this->getConfig($defaultDriver); |
105 | | - |
106 | | - // We get Symfony Transport from Laravel 9 mailer |
107 | | - if (version_compare(app()->version(), '10.0.0', '<')) { |
108 | | - $symfonyTransport = $app['mail.manager']->getSymfonyTransport(); |
109 | | - } else { |
110 | | - $symfonyTransport = $app['mailer']->getSymfonyTransport(); |
111 | | - } |
112 | | - |
113 | | - // Once we have create the mailer instance, we will set a container instance |
114 | | - // on the mailer. This allows us to resolve mailer classes via containers |
115 | | - // for maximum testability on said classes instead of passing Closures. |
116 | | - $mailer = new Laravel9Mailer( |
| 21 | + $mailer = new GeneralLaravelMailer( |
117 | 22 | 'smtp', |
118 | 23 | $app['view'], |
119 | 24 | $symfonyTransport, |
@@ -152,11 +57,7 @@ protected function getConfig($name = 'smtp') |
152 | 57 | */ |
153 | 58 | protected function setGlobalAddress($mailer, array $config, $type) |
154 | 59 | { |
155 | | - if (version_compare(app()->version(), '7.0.0', '<')) { |
156 | | - $address = Arr::get($config, $type); |
157 | | - } else { |
158 | | - $address = Arr::get($config, $type, $this->app['config']['mail.'.$type]); |
159 | | - } |
| 60 | + $address = Arr::get($config, $type, $this->app['config']['mail.'.$type]); |
160 | 61 |
|
161 | 62 | if (is_array($address) && isset($address['address'])) { |
162 | 63 | $mailer->{'always'.Str::studly($type)}($address['address'], $address['name']); |
|
0 commit comments