1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 18:04:03 +00:00

Allow mapping nested tenant properties to mail config (#20)

* Use data_get() to allow mapping nested tenant attributes to mail config

* Fix code style (php-cs-fixer)

* Test the data_get() change

* Improve code, add info to docblock

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
This commit is contained in:
lukinovec 2023-12-18 12:42:03 +01:00 committed by GitHub
parent ca400b51d2
commit ea5a7463b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 3 deletions

View file

@ -16,7 +16,8 @@ class MailTenancyBootstrapper implements TenancyBootstrapper
*
* For example:
* [
* 'config.key.name' => 'tenant_property',
* 'config.key.username' => 'tenant_property',
* 'config.key.password' => 'nested.tenant_property',
* ]
*/
public static array $credentialsMap = [];
@ -60,9 +61,9 @@ class MailTenancyBootstrapper implements TenancyBootstrapper
protected function setConfig(Tenant $tenant): void
{
foreach (static::$credentialsMap as $configKey => $storageKey) {
$override = $tenant->$storageKey;
$override = data_get($tenant, $storageKey);
if (array_key_exists($storageKey, $tenant->getAttributes())) {
if ($override !== null) {
$this->originalConfig[$configKey] ??= $this->config->get($configKey);
$this->config->set($configKey, $override);