Skip to content

Commit 46c5ce5

Browse files
committed
Remove support for Laravel 8 and 9, consolidate to GeneralLaravelMailer
1 parent d3566f7 commit 46c5ce5

File tree

4 files changed

+7
-62
lines changed

4 files changed

+7
-62
lines changed

src/CreatesMailers.php

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,22 @@
44

55
use Illuminate\Support\Arr;
66
use Illuminate\Support\Str;
7-
use Swift_Mailer;
87

98
trait CreatesMailers
109
{
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-
}
3810

39-
return $mailer;
40-
}
41-
42-
protected function createLaravel9Mailer($app)
11+
protected function createGeneralLaravelMailer($app)
4312
{
4413
$defaultDriver = $app['mail.manager']->getDefaultDriver();
4514
$config = $this->getConfig($defaultDriver);
4615

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();
5318

5419
// Once we have create the mailer instance, we will set a container instance
5520
// on the mailer. This allows us to resolve mailer classes via containers
5621
// for maximum testability on said classes instead of passing Closures.
57-
$mailer = new Laravel9Mailer(
22+
$mailer = new GeneralLaravelMailer(
5823
'smtp',
5924
$app['view'],
6025
$symfonyTransport,
@@ -93,11 +58,7 @@ protected function getConfig($name = 'smtp')
9358
*/
9459
protected function setGlobalAddress($mailer, array $config, $type)
9560
{
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]);
10162

10263
if (is_array($address) && isset($address['address'])) {
10364
$mailer->{'always'.Str::studly($type)}($address['address'], $address['name']);

src/Laravel8Mailer.php renamed to src/GeneralLaravelMailer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Contracts\Mail\Factory as MailFactory;
66
use Illuminate\Contracts\Mail\Mailer as MailerContract;
77

8-
class Laravel8Mailer extends Mailer implements MailerContract, MailFactory
8+
class GeneralLaravelMailer extends Mailer implements MailerContract, MailFactory
99
{
1010
public $currentMailer = null;
1111
protected $app;

src/HeloLaravelServiceProvider.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,7 @@ public function register()
4545
$this->mergeConfigFrom(__DIR__.'/../config/helo.php', 'helo');
4646

4747
$this->app->singleton(Mailer::class, function ($app) {
48-
$version = $this->version($app);
49-
50-
if ($version < 9) {
51-
return $this->createLaravel8Mailer($app);
52-
}
53-
54-
return $this->createLaravel9Mailer($app);
48+
return $this->createGeneralLaravelMailer($app);
5549
});
5650
}
5751

src/Laravel9Mailer.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)