Repository navigation
Support list configuration values via JSON arrays - #27
Conversation
8170df4 to
81b00fb
Compare
snake14
left a comment
There was a problem hiding this comment.
Thanks @mbrodala! Tested locally: JSON arrays now work for trusted_hosts and Plugins[].
Medium
Scalars are decoded too, which can break existing setups. E.g. a password 1e3 becomes 1000, a long all-digit salt becomes a float, and false/null stop being strings. Could you keep only array results and fall back to the raw string otherwise?
$settingValue = is_array($decoded) ? $decoded : $envValue;Then the README should say that only JSON arrays/objects are decoded.
Changelog and version: please add a CHANGELOG.md entry and bump plugin.json (6.0.0 is already released).
Tests: a small test for an array, malformed JSON and a few scalars would cover this.
Low
- The new README paragraph is hard-wrapped, unlike the rest of the file.
$eis unused;catch (\JsonException)is enough on PHP 8.1+.
|
I'd gladly add tests but don't see any existing infrastructure for this. Adding one would be out of scope for this change. Or did I miss something? I'll adapt the other suggestions. |
There was a problem hiding this comment.
Thanks for the updates @mbrodala, scalars now stay strings as expected. 👍
One bug left, plus a small release tweak:
Blocking: when json_decode throws, $decodedEnvValue is never assigned, so line 30 reads either an undefined variable or the value left over from an earlier variable in the loop. Locally, MATOMO_GENERAL_GEOLOCATION_DOWNLOAD_FROM_TRUSTED_HOSTS='["a.example","b.example"]' followed by MATOMO_GENERAL_LOGIN_COOKIE_NAME=mycookie turned login_cookie_name into that array. PHPStan also flags line 30. Setting $decodedEnvValue = null; in the catch (instead of $settingValue = $envValue;) fixes both.
Version: please make this 6.0.1 rather than 6.1.0, with a changelog entry like the following:
### 6.0.1 - 2026-10-05
- Environment variable values can now be set as JSON arrays, eg for `trusted_hosts`
Good point about there being no test setup yet, so no need for tests here.
dcc243d to
0a12ce3
Compare
|
@snake14 I've adjusted everything as expected. Since this is basically a new feature I went for 6.1.0 as per SemVer but I'm fine with anything here. |
Configuration options which expect a list of values are now supported by JSON arrays in environment variables. In case JSON parsing fails, the environment variable value is used literally just like before.
Description
All environment variables are now tried to be parsed as JSON which allows e.g. filling array setting values.
In case JSON parsing fails, the environment variable value is used literally just like before.
Issue No
Fixes #9
Steps to Replicate the Issue
MATOMO_GENERAL_TRUSTED_HOSTS=["192.168.1.1","192.168.2.1"]arrayinternally.Checklist