Changeset View
Changeset View
Standalone View
Standalone View
src/app/Traits/UserConfigTrait.php
<?php | <?php | ||||
namespace App\Traits; | namespace App\Traits; | ||||
trait UserConfigTrait | trait UserConfigTrait | ||||
{ | { | ||||
/** | /** | ||||
* A helper to get the user configuration. | * A helper to get the user configuration. | ||||
*/ | */ | ||||
public function getConfig(): array | public function getConfig(): array | ||||
{ | { | ||||
$config = []; | $config = []; | ||||
// TODO: Should we store the default value somewhere in config? | // TODO: Should we store the default value somewhere in config? | ||||
$config['greylist_enabled'] = $this->getSetting('greylist_enabled') !== 'false'; | $config['greylisting'] = $this->getSetting('greylist_enabled') !== 'false'; | ||||
return $config; | return $config; | ||||
} | } | ||||
/** | /** | ||||
* A helper to update user configuration. | * A helper to update user configuration. | ||||
* | * | ||||
* @param array $config An array of configuration options | * @param array $config An array of configuration options | ||||
* | * | ||||
* @return array A list of input validation error messages | * @return array A list of input validation error messages | ||||
*/ | */ | ||||
public function setConfig(array $config): array | public function setConfig(array $config): array | ||||
{ | { | ||||
$errors = []; | $errors = []; | ||||
foreach ($config as $key => $value) { | foreach ($config as $key => $value) { | ||||
if ($key == 'greylist_enabled') { | if ($key == 'greylisting') { | ||||
$this->setSetting('greylist_enabled', $value ? 'true' : 'false'); | $this->setSetting('greylist_enabled', $value ? 'true' : 'false'); | ||||
} else { | } else { | ||||
$errors[$key] = \trans('validation.invalid-config-parameter'); | $errors[$key] = \trans('validation.invalid-config-parameter'); | ||||
} | } | ||||
} | } | ||||
return $errors; | return $errors; | ||||
} | } | ||||
} | } |