Repository navigation
fix(config): close the review findings carried over from 2.0.8 - #14235
Conversation
A non-public schema property reached `$instance->$name = $value` from Config's scope and threw a raw Error. An absent optional key left a typed property without a default uninitialised, so the returned object failed on first read. Both now raise Load: properties must be public, and an absent optional key keeps the declared default, becomes null on a nullable property, or is reported missing. The validator and missing-type tests sent `KEY` to a schema reading `key`, so they failed on the missing required key and stayed green with their checks removed. They now send `key` and pin the message of the path they cover.
Parser\PHP includes the contents, so anything before `<?php`, or a file with no open tag at all, was printed to output and only then rejected because include returned 1. It now refuses such contents before including them. The test covers a missing tag, text, a newline and a byte order mark before it, and asserts nothing is printed. Three existing tests built their fixtures with heredocs that left four spaces before the tag, which were being printed; their closing markers now strip that indentation.
An unquoted value was cut at its first `#`, so `pa#ss` became `pa` and a URL lost its fragment; `export KEY=value` was stored under `export KEY`. A `#` now starts a comment only at the start of the value or after whitespace, and a leading `export` is dropped from the key, matching common dotenv implementations. Repository env detection reads `.env` files through this parser, so the Gitea detection test covers both.
The getting-started config.json had a trailing comma that json_decode() rejects, and the variable-source example passed a positional argument after named ones and used `Whitelist` with string arguments instead of `WhiteList` with a list. Both now run as written. A new section states what Config::load() and Parser\PHP accept.
Rector would make the non-public fixture property readonly and give the nullable optional fixtures a null default, which removes the case the optional-key test covers. The non-public fixture is protected, and the default-null rule is skipped for ConfigTest.
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
This PR introduces a standalone
Reviewed commit: 2a3da2c |
🟢 Tier S · Ready to mergeThe pull request adds schema visibility checks and defined handling for absent optional keys, rejects PHP configuration content before the opening tag, and updates dotenv parsing to preserve embedded hashes and recognize export prefixes. It also corrects README examples and adds regression coverage, including Gitea environment detection. The latest changes implement the parser checks with string operations and whitespace checks instead of regular expressions. Latest changes: The newest commit replaces regex-based dotenv comment detection, export-prefix stripping, and PHP opening-tag validation with string operations and ctype_space checks.
📂 Walkthrough · 9
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 32 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
AGENTS.md rules out new preg_* calls. The dotenv comment cut, the export prefix and the PHP open-tag check use string functions instead; ctype_space matches the same characters as PCRE's \s, and the comment cut keeps the regex's cut point (before the whitespace), so results are unchanged.
Summary
Fixes the review findings on #14227 that sat in
utopia-php/config2.0.8 as released, and were left unchanged there because absorb PRs only move code. Part of #13828.ErrorConfig::load()rejects any non-public property withLoadbefore assigning.null; any other property raisesLoadinstead of returning an object that fails on first read. Applies to#[Key]and#[ConfigKey].KEYto a schema readingkeytestExceptionValidatorandtestExceptionWithoutTypesendkeyand pin the message of the path they cover.Parser\PHPprints tag-less config<?php. Anything before it (missing tag, text, a newline, a BOM) is rejected withParsebeforeinclude.#and mis-keysexport#starts a comment only at the start of the value or after whitespace, sopa#ssandhttps://x.com/a#bstay whole. A leadingexportis dropped from the key.new WhiteList(['high', 'low']), and the combined example usesWhiteListtoo. A new "Schema rules" section states the loader andParser\PHPcontract.The last commit (2a3da2c) keeps the fixtures in the shape under test. Rector would make the non-public fixture property
readonlyand give the nullable optional fixtures anulldefault, which removes the case the optional-key test covers. So the non-public fixture isprotected, andRestoreDefaultNullToNullableTypePropertyRectoris skipped fortests/ConfigTest.phponly.Three existing
PHPTestfixtures used heredocs that left four spaces before<?php.includewas printing those, and the new open-tag rule rejects them, so their closing markers now strip the indentation.Effect on Appwrite
Appwrite and Cloud use only the registry (
setParam/getParam) andParser\Dotenv, the latter in repository env detection (Detections/Create,Repositories/XList). Detection now keepsSECRET=pa#sswhole and readsexport EXPORTED=yesasEXPORTED. The Gitea e2e testtestDetectionReadsVariablesFromDotenvcovers both. Nothing in Appwrite or Cloud calls the typed loader orParser\PHP.Release
Not released here. If a semver-strict call is wanted, three changes alter what previously accepted input produces:
Load.<?phpused to parse (after printing that text). They are now rejected.#, and keys behindexport, parse differently.That argues for
config/3.0.0. The non-public check and the nullable-becomes-null case only turn a fatal intoLoador a usable object, so they would be fine in a minor. Since no consumer uses the typed loader orParser\PHP(Edge and open-runtimes/executor are on the 0.2 registry),2.2.0with these called out in the notes is also defensible. The Dotenv change is the only one an existing consumer (Appwrite env detection) sees, and there it is a fix.Tests
Each fix was seen red: I reverted the hunk and the new or corrected tests failed, then passed with it restored.
leaveUnsetremoved: the usable-object test errors and the no-default test fails.testExceptionValidator/testExceptionWithoutTypefail. Before this PR they stayed green with those checks removed.testPHPParseExceptionMissingStartcases fail.#andexporttests fail.Parse, and the variable-source example is a fatal ("positional argument after named argument"). Both now run and dump the loaded object.Results:
bin/monorepo check configandbin/monorepo test config: 84 tests / 282 assertions.packagessuite filtered toUtopia\Configinappwrite/base:2.1.0: 84 tests pass. Appwriteunitsuite: 1397 tests pass.composer lint,composer refactor:check, PHPStan (no errors, with no stale baseline entries) andbin/monorepo validatepass..envfixture. The test itself runs in CI'sVCSGiteajob.