-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Octane] Error because of MailManager replacement #27
Comments
Hi @maxeckel, A Laravel8Mailer class would be a great solution for this. A PR would be great, thank you! :) |
Hey @mpociot, Thanks for the update! I'll add a PR as soon as possible! |
@maxeckel any updates on a PR for this? |
I got this running, but I haven't tested it fully src/HeloLaravelServiceProvider.php /**
* Register the application services.
*/
public function register()
{
...
$this->app->singleton(Mailer::class, function ($app) {
if (version_compare($app->version(), '7.0.0', '<')) {
return $this->createLaravel6Mailer($app);
}
//---[Changed]---
if (version_compare($app->version(), '8.0.0', '<')) {
return $this->createLaravel7Mailer($app);
}
return $this->createLaravel8Mailer($app);
});
} //Added method
protected function createLaravel8Mailer($app)
{
$defaultDriver = $app['mail.manager']->getDefaultDriver();
$config = $this->getConfig($defaultDriver);
// Laravel 7 no longer bindes the swift.mailer:
$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;
} New src/Laravel8Mailer.php <?php
namespace BeyondCode\HeloLaravel;
use Illuminate\Contracts\Mail\Factory as MailFactory;
use Illuminate\Contracts\Mail\Mailer as MailerContract;
class Laravel8Mailer extends Mailer implements MailerContract, MailFactory
{
public function mailer($name = null)
{
$this->currentMailer = $name;
return $this;
}
/**
* 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;
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Folks,
I've just installed Octane (using Swoole) in a project where also Helo is used.
The Workers constantly throw errors, telling that "setApplication()" does not exist on the Laravel7Mailer:
I've chased this down to the call to
Mail::swap($instance)
in the HeloLaravelServiceProvider:26 .As by calling this method the underlying MailManager binding is swapped, this error appears.
If you are fine with e.g. adding a new Laravel8Mailer (which would add support for the setApplication method), as Octane requires Laravel 8, I'd be happy to PR this addition :)
If you have another solution in mind (like adding the methods on the current mailer), I'd also be happy to take on the implementation ;)
Best regards,
Max
The text was updated successfully, but these errors were encountered: