feat(overrides): modify outgoing setting values
Signed-off-by: miguel456 <me@nogueira.codes>
This commit is contained in:
parent
05e2cd4f82
commit
17652307c8
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user