Skip to content

Commit bcd2be6

Browse files
authored
Merge pull request #28 from orkhanahmadov/master
Laravel 9 support
2 parents bca9d97 + 88df5d2 commit bcd2be6

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ build
22
composer.lock
33
docs
44
vendor
5-
coverage
5+
coverage
6+
.phpunit.result.cache
7+
.idea

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ language: php
33
php:
44
- 7.3
55
- 7.4
6+
- 8.0
7+
- 8.1
68

79
env:
810
matrix:

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
],
1818
"require": {
1919
"php": "^7.3|^8.0",
20-
"illuminate/view": "^6.0|^7.0|^8.0",
21-
"illuminate/console": "^6.0|^7.0|^8.0",
22-
"illuminate/mail": "^6.0|^7.0|^8.0"
20+
"illuminate/view": "^6.0|^7.0|^8.0|^9.0",
21+
"illuminate/console": "^6.0|^7.0|^8.0|^9.0",
22+
"illuminate/mail": "^6.0|^7.0|^8.0|^9.0"
2323
},
2424
"require-dev": {
25-
"orchestra/testbench": "^5.1|^6.3",
25+
"orchestra/testbench": "^5.1|^6.3|^7.0",
2626
"phpunit/phpunit": "^8.0|^9.0"
2727
},
2828
"autoload": {
@@ -42,6 +42,7 @@
4242
"config": {
4343
"sort-packages": true
4444
},
45+
"minimum-stability": "dev",
4546
"extra": {
4647
"laravel": {
4748
"providers": [

src/HeloLaravelServiceProvider.php

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function boot()
2626
Mail::swap($instance);
2727

2828
app()->instance(MailerContract::class, $instance);
29-
29+
3030
if ($this->app->runningInConsole()) {
3131
View::addNamespace('helo', __DIR__ . '/../resources/views');
3232
}
@@ -41,7 +41,7 @@ public function register()
4141
$this->commands([
4242
TestMailCommand::class,
4343
]);
44-
44+
4545
$this->publishes([
4646
__DIR__.'/../config/helo.php' => base_path('config/helo.php'),
4747
], 'config');
@@ -50,11 +50,16 @@ public function register()
5050
$this->mergeConfigFrom(__DIR__.'/../config/helo.php', 'helo');
5151

5252
$this->app->singleton(Mailer::class, function ($app) {
53-
if (version_compare($app->version(), '7.0.0', '<')) {
53+
$version = (int) Str::of($app->version())->explode('.')->first();
54+
55+
if ($version < 7) {
5456
return $this->createLaravel6Mailer($app);
5557
}
58+
if ($version < 9) {
59+
return $this->createLaravel7Mailer($app);
60+
}
5661

57-
return $this->createLaravel7Mailer($app);
62+
return $this->createLaravel9Mailer($app);
5863
});
5964
}
6065

@@ -112,6 +117,35 @@ protected function createLaravel7Mailer($app)
112117
return $mailer;
113118
}
114119

120+
protected function createLaravel9Mailer($app)
121+
{
122+
$defaultDriver = $app['mail.manager']->getDefaultDriver();
123+
$config = $this->getConfig($defaultDriver);
124+
125+
// We get Symfony Transport from Laravel 9 mailer
126+
$symfonyTransport = $app['mail.manager']->getSymfonyTransport();
127+
128+
// Once we have create the mailer instance, we will set a container instance
129+
// on the mailer. This allows us to resolve mailer classes via containers
130+
// for maximum testability on said classes instead of passing Closures.
131+
$mailer = new Laravel7Mailer(
132+
'smtp', $app['view'], $symfonyTransport, $app['events']
133+
);
134+
135+
if ($app->bound('queue')) {
136+
$mailer->setQueue($app['queue']);
137+
}
138+
139+
// Next we will set all of the global addresses on this mailer, which allows
140+
// for easy unification of all "from" addresses as well as easy debugging
141+
// of sent messages since they get be sent into a single email address.
142+
foreach (['from', 'reply_to', 'to', 'return_path'] as $type) {
143+
$this->setGlobalAddress($mailer, $config, $type);
144+
}
145+
146+
return $mailer;
147+
}
148+
115149
protected function getConfig($name = 'smtp')
116150
{
117151
return $this->app['config']['mail.driver']

0 commit comments

Comments
 (0)