Handle 0s and 1s

This commit is contained in:
Marcin Łojewski
2018-12-25 10:01:53 +01:00
parent a3a2a90d87
commit 7f84113bca
3 changed files with 50 additions and 17 deletions

View File

@@ -399,7 +399,7 @@ class SettingsController extends Controller
"CRYPTO_PARAM_" . $key
)];
if (!empty($param)) {
if (!is_null($param)) {
$value->value = $param;
}
}

View File

@@ -70,7 +70,8 @@ class Properties implements \ArrayAccess
*/
public function __construct(
$AppName, IConfig $config, ILogger $logger, Cache $cache
) {
)
{
$this->appName = $AppName;
$this->config = $config;
$this->logger = $logger;
@@ -99,10 +100,12 @@ class Properties implements \ArrayAccess
foreach ($params as $param) {
$value = $this->config->getAppValue($this->appName, $param, null);
if ($value === App::FALSE_VALUE) {
$value = false;
} elseif ($value === App::TRUE_VALUE) {
$value = true;
if ($this->isBooleanParam($param)) {
if ($value === App::FALSE_VALUE) {
$value = false;
} elseif ($value === App::TRUE_VALUE) {
$value = true;
}
}
$this->data[$param] = $value;
@@ -116,6 +119,24 @@ class Properties implements \ArrayAccess
);
}
/**
* Is given parameter a boolean parameter.
*
* @param $param string Parameter name.
*
* @return bool Is a boolean parameter.
*/
private function isBooleanParam($param)
{
return in_array(
$param, [
Opt::APPEND_SALT, Opt::CASE_INSENSITIVE_USERNAME,
Opt::NAME_CHANGE, Opt::PASSWORD_CHANGE, Opt::PREPEND_SALT,
Opt::REVERSE_ACTIVE, Opt::USE_CACHE
]
);
}
/**
* Return an array with all supported parameters.
*
@@ -186,10 +207,12 @@ class Properties implements \ArrayAccess
{
$this->config->setAppValue($this->appName, $offset, $value);
if ($value === App::FALSE_VALUE) {
$value = false;
} elseif ($value === App::TRUE_VALUE) {
$value = true;
if ($this->isBooleanParam($offset)) {
if ($value === App::FALSE_VALUE) {
$value = false;
} elseif ($value === App::TRUE_VALUE) {
$value = true;
}
}
$this->data[$offset] = $value;