Skip to content

Commit b99df6f

Browse files
committed
wip
1 parent 80beac7 commit b99df6f

File tree

5 files changed

+73
-5
lines changed

5 files changed

+73
-5
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"homepage": "https://github.com/beyondcode/helo-laravel",
1818
"require": {
1919
"php": "^8.0 || ^8.1 || ^8.2",
20-
"illuminate/console": "^9.0 || ^10.0 || ^11.0",
21-
"illuminate/mail": "^9.0 || ^10.0 || ^11.0",
22-
"illuminate/view": "^9.0 || ^10.0 || ^11.0"
20+
"illuminate/console": "^8.0 || ^9.0 || ^10.0 || ^11.0",
21+
"illuminate/mail": "^8.0 || ^9.0 || ^10.0 || ^11.0",
22+
"illuminate/view": "^8.0 || ^9.0 || ^10.0 || ^11.0"
2323
},
2424
"require-dev": {
2525
"orchestra/testbench": "^7.0 || ^8.0 || ^9.0",

src/CreatesMailers.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,38 @@ protected function createLaravel7Mailer($app)
6767
return $mailer;
6868
}
6969

70+
protected function createLaravel8Mailer($app)
71+
{
72+
$defaultDriver = $app['mail.manager']->getDefaultDriver();
73+
$config = $this->getConfig($defaultDriver);
74+
75+
$swiftMailer = new Swift_Mailer($app['mail.manager']->createTransport($config));
76+
77+
78+
// Once we have create the mailer instance, we will set a container instance
79+
// on the mailer. This allows us to resolve mailer classes via containers
80+
// for maximum testability on said classes instead of passing Closures.
81+
$mailer = new Laravel8Mailer(
82+
'smtp',
83+
$app['view'],
84+
$swiftMailer,
85+
$app['events']
86+
);
87+
88+
if ($app->bound('queue')) {
89+
$mailer->setQueue($app['queue']);
90+
}
91+
92+
// Next we will set all of the global addresses on this mailer, which allows
93+
// for easy unification of all "from" addresses as well as easy debugging
94+
// of sent messages since they get be sent into a single email address.
95+
foreach (['from', 'reply_to', 'to', 'return_path'] as $type) {
96+
$this->setGlobalAddress($mailer, $config, $type);
97+
}
98+
99+
return $mailer;
100+
}
101+
70102
protected function createLaravel9Mailer($app)
71103
{
72104
$defaultDriver = $app['mail.manager']->getDefaultDriver();

src/HeloLaravelServiceProvider.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ public function register()
5050
if ($version < 7) {
5151
return $this->createLaravel6Mailer($app);
5252
}
53-
if ($version < 9) {
53+
54+
if ($version < 8) {
5455
return $this->createLaravel7Mailer($app);
5556
}
5657

58+
if ($version < 9) {
59+
return $this->createLaravel8Mailer($app);
60+
}
61+
5762
return $this->createLaravel9Mailer($app);
5863
});
5964
}

src/Laravel8Mailer.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace BeyondCode\HeloLaravel;
4+
5+
use Illuminate\Contracts\Mail\Factory as MailFactory;
6+
use Illuminate\Contracts\Mail\Mailer as MailerContract;
7+
8+
class Laravel8Mailer extends Laravel7Mailer implements MailerContract, MailFactory
9+
{
10+
/**
11+
* Set laravel application.
12+
*
13+
* @param \Illuminate\Contracts\Container\Container $app
14+
*/
15+
// public function setApplication($app)
16+
// {
17+
// $this->app = $app;
18+
// }
19+
20+
/**
21+
* Forget all of the resolved mailer instances.
22+
*
23+
* @return $this
24+
*/
25+
// public function forgetMailers()
26+
// {
27+
// $this->mailers = [];
28+
29+
// return $this;
30+
// }
31+
}

src/Laravel9Mailer.php

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

8-
class Laravel9Mailer extends Laravel7Mailer implements MailerContract, MailFactory
8+
class Laravel9Mailer extends Laravel8Mailer implements MailerContract, MailFactory
99
{
1010
}

0 commit comments

Comments
 (0)