mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 18:14:04 +00:00
Add comments to TenancyMailManager, rename property
This commit is contained in:
parent
3336729b14
commit
64aa0c895b
1 changed files with 28 additions and 2 deletions
|
|
@ -5,16 +5,42 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy; // todo new Overrides namespace?
|
namespace Stancl\Tenancy; // todo new Overrides namespace?
|
||||||
|
|
||||||
use Illuminate\Mail\MailManager;
|
use Illuminate\Mail\MailManager;
|
||||||
|
use Stancl\Tenancy\Bootstrappers\MailTenancyBootstrapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class (paired with the MailTenancyBootstrapper)
|
||||||
|
* allows tenants to have their custom mailer credentials.
|
||||||
|
*
|
||||||
|
* Tenancy swaps Laravel's MailManager singleton for an instance of this class,
|
||||||
|
* which overrides the manager's get method to always resolve
|
||||||
|
* the mailers specified in the static $mailersToAlwaysResolve property
|
||||||
|
* instead of getting them from the $mailers property where they're cached.
|
||||||
|
*
|
||||||
|
* This is mainly used to solve the issue where
|
||||||
|
* mail gets sent with the incorrect (old) mailer credentials
|
||||||
|
* due to the mailer being cached in the manager's $mailers property
|
||||||
|
* and not getting updated when the tenant's credentials change.
|
||||||
|
*
|
||||||
|
* @see MailTenancyBootstrapper
|
||||||
|
*/
|
||||||
class TenancyMailManager extends MailManager
|
class TenancyMailManager extends MailManager
|
||||||
{
|
{
|
||||||
public static array $mailersToNotCache = [
|
/**
|
||||||
|
* Names of mailers which will always get re-resolved even when they're
|
||||||
|
* cached & available in the $mailers property.
|
||||||
|
*/
|
||||||
|
public static array $mailersToAlwaysResolve = [
|
||||||
'smtp',
|
'smtp',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override the get method so that the mailers in $mailersToAlwaysResolve
|
||||||
|
* always get resolved even when they're cached and available in the $mailers property
|
||||||
|
* for the mailers to have the up-to-date tenant credentials.
|
||||||
|
*/
|
||||||
protected function get($name)
|
protected function get($name)
|
||||||
{
|
{
|
||||||
if (in_array($name, static::$mailersToNotCache)) {
|
if (in_array($name, static::$mailersToAlwaysResolve)) {
|
||||||
return $this->resolve($name);
|
return $this->resolve($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue