Better Env management for boolean keys.

This commit is contained in:
abdulmohsen
2024-05-16 17:37:22 +03:00
parent fc77f33d88
commit 09532f232f
3 changed files with 49 additions and 11 deletions

View File

@@ -120,6 +120,8 @@ final class Env
return api_response(HTTP_STATUS::HTTP_NOT_MODIFIED);
}
$value = (string)$value;
// -- check if the string contains space but not quoted.
// symfony/dotenv throws an exception if the value contains a space but not quoted.
if (str_contains($value, ' ') && (!str_starts_with($value, '"') || !str_ends_with($value, '"'))) {
@@ -139,6 +141,10 @@ final class Env
]), HTTP_STATUS::HTTP_BAD_REQUEST);
}
if ('bool' === ag($spec, 'type')) {
settype($value, 'bool');
}
$this->envFile->set($key, $value)->persist();
return api_response(HTTP_STATUS::HTTP_OK, [