Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mechelon committed Mar 13, 2024
1 parent 80beac7 commit b99df6f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 32 additions & 0 deletions src/CreatesMailers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion src/HeloLaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
31 changes: 31 additions & 0 deletions src/Laravel8Mailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace BeyondCode\HeloLaravel;

use Illuminate\Contracts\Mail\Factory as MailFactory;
use Illuminate\Contracts\Mail\Mailer as MailerContract;

class Laravel8Mailer extends Laravel7Mailer implements MailerContract, MailFactory
{
/**
* Set laravel application.
*
* @param \Illuminate\Contracts\Container\Container $app
*/
// public function setApplication($app)
// {
// $this->app = $app;
// }

/**
* Forget all of the resolved mailer instances.
*
* @return $this
*/
// public function forgetMailers()
// {
// $this->mailers = [];

// return $this;
// }
}
2 changes: 1 addition & 1 deletion src/Laravel9Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}

0 comments on commit b99df6f

Please sign in to comment.