feat(overrides): modify outgoing setting values

Signed-off-by: miguel456 <me@nogueira.codes>
This commit is contained in:
Miguel Nogueira 2023-06-29 18:19:04 +01:00
parent 05e2cd4f82
commit 17652307c8
No known key found for this signature in database
GPG Key ID: 3C6A7E29AF26D370

View File

@ -65,10 +65,10 @@ class Options
Cache::put($option, $value->option_value);
Cache::put($option.'_desc', 'Undefined description');
return $value->option_value;
return $this->modifyResponse($option, $value->option_value);
}
return $value;
return $this->modifyResponse($option, $value);
}
@ -189,4 +189,36 @@ class Options
return config("local-overrides.features.$option");
}
/**
* Modifies the outgoing option value according to its override value
*
* @param int $value Setting value
* @return int Modified setting value accordidng to business rules
*/
private function modifyResponse(string $option, int $value): int
{
$modifiedValue = $value;
try {
if ($this->isOverriden($option) && $this->getOverride($option) == Overrides::forceEnable->value) {
$modifiedValue = Overrides::forceEnable->value;
}
if ($this->isOverriden($option) && $this->getOverride($option) == Overrides::killSwitch->value) {
$modifiedValue = 0;
}
} catch (LogicException $exception) {
Log::debug('Illegal attempt to modify setting value: not overridable; not modifying', [
'msg' => $exception->getMessage()
]);
return $value;
}
return $modifiedValue;
}
}