Skip to content

Support list configuration values via JSON arrays - #27

Merged
snake14 merged 2 commits into
matomo-org:6.x-devfrom
mbrodala:patch-1
Oct 6, 2026
Merged

snake14 merged 2 commits into
matomo-org:6.x-devfrom
mbrodala:patch-1

Conversation

@mbrodala

@mbrodala mbrodala commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

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

  1. Set e.g. MATOMO_GENERAL_TRUSTED_HOSTS=["192.168.1.1","192.168.2.1"]
  2. Expected: the configured trusted hosts should be respected
  3. Actual: the configured trusted hosts are ignored since it is not an array internally.

Checklist

  • [✔] Tested locally or on demo2/demo3?
  • [NA] New test case added/updated?
  • [NA] Are all newly added texts included via translation?
  • [NA] Are text sanitized properly? (Eg use of v-text v/s v-html for vue)
  • [✔] Version bumped?
  • [NA] I have understood, reviewed, and tested all AI outputs before use
  • [NA] All AI instructions respect security, IP, and privacy rules
  • [✔] Documentation updated?

@mbrodala
mbrodala force-pushed the patch-1 branch 2 times, most recently from 8170df4 to 81b00fb Compare September 16, 2026 10:02
@mbrodala
mbrodala marked this pull request as ready for review September 16, 2026 10:07

@snake14 snake14 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
  • $e is unused; catch (\JsonException) is enough on PHP 8.1+.

@mbrodala

mbrodala commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

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.

@snake14 snake14 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mbrodala
mbrodala force-pushed the patch-1 branch 2 times, most recently from dcc243d to 0a12ce3 Compare October 6, 2026 11:18
@mbrodala

mbrodala commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@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.

@mbrodala mbrodala changed the title Support environment variable values as JSON Support list configuration values via JSON arrays Oct 6, 2026
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.

@snake14 snake14 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution and willingness to make adjustments @mbrodala .

@snake14
snake14 merged commit 4756515 into matomo-org:6.x-dev Oct 6, 2026
13 checks passed
snake14 added a commit that referenced this pull request Oct 19, 2026
…#29) (#32)

Configuration options which expect a list of values are now supported by
JSON arrays in environment variables. Values that are not a JSON array or
object are used literally, as before. The decode avoids JsonException for
PHP 7.2.

Co-authored-by: Mathias Brodala <mbrodala@pagemachine.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need a way to set trusted host

2 participants