diff --git a/composer.json b/composer.json index 7e2449f..15c2d68 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,9 @@ "homepage": "https://github.com/beyondcode/helo-laravel", "require": { "php": "^8.0 || ^8.1 || ^8.2", - "illuminate/console": "^9.0 || ^10.0 || ^11.0", - "illuminate/mail": "^9.0 || ^10.0 || ^11.0", - "illuminate/view": "^9.0 || ^10.0 || ^11.0" + "illuminate/console": "^8.0 || ^9.0 || ^10.0 || ^11.0", + "illuminate/mail": "^8.0 || ^9.0 || ^10.0 || ^11.0", + "illuminate/view": "^8.0 || ^9.0 || ^10.0 || ^11.0" }, "require-dev": { "orchestra/testbench": "^7.0 || ^8.0 || ^9.0", diff --git a/src/CreatesMailers.php b/src/CreatesMailers.php index a3615c2..30d89f9 100644 --- a/src/CreatesMailers.php +++ b/src/CreatesMailers.php @@ -67,6 +67,38 @@ protected function createLaravel7Mailer($app) return $mailer; } + protected function createLaravel8Mailer($app) + { + $defaultDriver = $app['mail.manager']->getDefaultDriver(); + $config = $this->getConfig($defaultDriver); + + $swiftMailer = new Swift_Mailer($app['mail.manager']->createTransport($config)); + + + // Once we have create the mailer instance, we will set a container instance + // on the mailer. This allows us to resolve mailer classes via containers + // for maximum testability on said classes instead of passing Closures. + $mailer = new Laravel8Mailer( + 'smtp', + $app['view'], + $swiftMailer, + $app['events'] + ); + + if ($app->bound('queue')) { + $mailer->setQueue($app['queue']); + } + + // Next we will set all of the global addresses on this mailer, which allows + // for easy unification of all "from" addresses as well as easy debugging + // of sent messages since they get be sent into a single email address. + foreach (['from', 'reply_to', 'to', 'return_path'] as $type) { + $this->setGlobalAddress($mailer, $config, $type); + } + + return $mailer; + } + protected function createLaravel9Mailer($app) { $defaultDriver = $app['mail.manager']->getDefaultDriver(); diff --git a/src/HeloLaravelServiceProvider.php b/src/HeloLaravelServiceProvider.php index 0845afa..7f24e9d 100644 --- a/src/HeloLaravelServiceProvider.php +++ b/src/HeloLaravelServiceProvider.php @@ -50,10 +50,15 @@ public function register() if ($version < 7) { return $this->createLaravel6Mailer($app); } - if ($version < 9) { + + if ($version < 8) { return $this->createLaravel7Mailer($app); } + if ($version < 9) { + return $this->createLaravel8Mailer($app); + } + return $this->createLaravel9Mailer($app); }); } diff --git a/src/Laravel8Mailer.php b/src/Laravel8Mailer.php new file mode 100644 index 0000000..d945390 --- /dev/null +++ b/src/Laravel8Mailer.php @@ -0,0 +1,31 @@ +app = $app; + // } + + /** + * Forget all of the resolved mailer instances. + * + * @return $this + */ + // public function forgetMailers() + // { + // $this->mailers = []; + + // return $this; + // } +} diff --git a/src/Laravel9Mailer.php b/src/Laravel9Mailer.php index bd6fb6e..a36093c 100644 --- a/src/Laravel9Mailer.php +++ b/src/Laravel9Mailer.php @@ -5,6 +5,6 @@ use Illuminate\Contracts\Mail\Factory as MailFactory; use Illuminate\Contracts\Mail\Mailer as MailerContract; -class Laravel9Mailer extends Laravel7Mailer implements MailerContract, MailFactory +class Laravel9Mailer extends Laravel8Mailer implements MailerContract, MailFactory { }