mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 16:14:03 +00:00
Add MailTenancyBootstrapper
This commit is contained in:
parent
73fec87e17
commit
b03a9ec3c0
1 changed files with 68 additions and 0 deletions
68
src/Bootstrappers/MailTenancyBootstrapper.php
Normal file
68
src/Bootstrappers/MailTenancyBootstrapper.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Bootstrappers;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Config\Repository;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
|
||||
class MailTenancyBootstrapper implements TenancyBootstrapper
|
||||
{
|
||||
protected array $originalConfig = [];
|
||||
|
||||
public function __construct(protected Repository $config)
|
||||
{
|
||||
}
|
||||
|
||||
public function bootstrap(Tenant $tenant): void
|
||||
{
|
||||
foreach ($this->credentialsMap() as $storageKey => $configKey) {
|
||||
/** @var Tenant&Model $tenant */
|
||||
$override = Arr::get($tenant, $storageKey);
|
||||
|
||||
if (! is_null($override)) {
|
||||
if (is_array($configKey)) {
|
||||
foreach ($configKey as $key) {
|
||||
$this->originalConfig[$key] = $this->originalConfig[$key] ?? $this->config->get($key);
|
||||
|
||||
$this->config->set($key, $override);
|
||||
}
|
||||
} else {
|
||||
$this->originalConfig[$configKey] = $this->originalConfig[$configKey] ?? $this->config->get($configKey);
|
||||
|
||||
$this->config->set($configKey, $override);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function revert(): void
|
||||
{
|
||||
foreach ($this->originalConfig as $key => $value) {
|
||||
$this->config->set($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tenant properties to be mapped to config (similarly the TenantConfig feature).
|
||||
*
|
||||
* For example:
|
||||
* [
|
||||
* 'property' => 'config.key.name',
|
||||
* ]
|
||||
*/
|
||||
protected function credentialsMap()
|
||||
{
|
||||
return [
|
||||
'smtp_transport' => 'mail.mailers.smtp.transport',
|
||||
'smtp_host' => 'mail.mailers.smtp.host',
|
||||
'smtp_port' => 'mail.mailers.smtp.port',
|
||||
'smtp_encryption' => 'mail.mailers.smtp.encryption',
|
||||
'smtp_username' => 'mail.mailers.smtp.username',
|
||||
'smtp_password' => 'mail.mailers.smtp.password',
|
||||
'smtp_timeout' => 'mail.mailers.smtp.timeout',
|
||||
'smtp_local_domain' => 'mail.mailers.smtp.local_domain',
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue