Repository navigation
chore: absorb utopia-php/config into packages/config - #14227
Conversation
fully-qualified function calls
…n Psalm analysis.
…idelines added Contributing.md
chore: widen utopia-php/validators to 0.3.*
docs: enforce documentation style with Vale
docs: centralize CODE_OF_CONDUCT and CONTRIBUTING at the monorepo root
Allow validators 0.4 in dependent packages
Allow validators 0.5 in dependent packages
chore: require validators 0.6
chore: adopt validators ^1.0 in config and storage
2.x replaced the 1.x registry (load/setParam/getParam) with a typed Source + Parser loader, which left every consumer (Appwrite, Cloud, Edge, open-runtimes/executor) on 1.x or 0.2. Config regains $params, setParam() and getParam() with the 1.x semantics, so 2.x can host both styles and consumers move without rewriting their call sites. load() stays the typed loader; registry users store values with setParam(). Also applies step A of the monorepo shape (flat src/ and tests/, Utopia\Config\Tests\), a level-max PHPStan config with a baseline for the 123 findings it arrived with, and sets the env-source fixture in the test itself since the root packages suite does not read the package phpunit.xml.
Drops the vendored utopia-php/config 1.0.0; packages/config now provides Utopia\Config\Config with the registry restored, so call sites keep their imports. The 45 file loads in app/init/configs.php store each file with setParam(include ...), since load() is 2.x's typed loader. Repository env detection moves to Parser\Dotenv, which honours quotes and maps a literal null to null; the response model types the value as a string, so a null is returned as ''. Refs #13828
|
Review complete. 🟡 5 medium 💬 Inline comments (5)
🧹 Nitpicks (2) — 🟢 2 low
This PR absorbs the config library into the monorepo as
Reviewed commit: a0fedff |
🟢 Tier S · Ready to mergeAbsorbs Utopia Config into Latest changes: Both repository detection endpoints now return
📂 Walkthrough · 10
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 32 existing findings tracked in
|
There was a problem hiding this comment.
Absorbs utopia-php/config into packages/config with parser/source rewrites, then migrates app/init/configs.php and the VCS dotenv endpoints to the new API.
Key findings
- 🟡 Literal
nulldotenv value becomes empty string — Dotenv.php:167 - 🟡 Non-public config properties throw raw
Error— Config.php:71 - 🟡 Optional missing keys leave typed properties uninitialized — Config.php:88
- 🟡 PHP parser echoes tag-less config to output — PHP.php:32
- 🟡 Dotenv truncates values at any
#, mis-keysexport— Dotenv.php:54
| foreach ($reflection->getProperties() as $property) { | ||
| $attributeFound = false; | ||
|
|
||
| foreach ($property->getAttributes(Key::class, ReflectionAttribute::IS_INSTANCEOF) as $attribute) { | ||
| $attributeFound = true; | ||
| $key = $attribute->newInstance(); | ||
|
|
||
| $value = self::resolveValue($data, $key->name); | ||
|
|
||
| // A present null is kept; only a genuinely absent key is skipped | ||
| // or, when required, reported missing. | ||
| if ($value === self::missing()) { | ||
| if ($key->required) { | ||
| throw new Load("Missing required key: {$key->name}"); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| $expectedType = $property->getType(); | ||
| if ($expectedType === null) { | ||
| throw new Load("Property {$property->name} is missing a type."); | ||
| } | ||
|
|
||
| if (! $key->validator->isValid($value)) { | ||
| throw new Load("Invalid value for {$key->name}: {$key->validator->getDescription()}"); | ||
| } | ||
|
|
||
| $propertyName = $property->name; | ||
| try { | ||
| $instance->$propertyName = $value; | ||
| } catch (\TypeError $e) { | ||
| throw new Load("Invalid value for {$key->name}: does not match the type of property {$property->name}.", 0, $e); | ||
| } | ||
| } | ||
|
|
||
| foreach ($property->getAttributes(ConfigKey::class, ReflectionAttribute::IS_INSTANCEOF) as $attribute) { | ||
| $attributeFound = true; | ||
|
|
||
| $key = $attribute->newInstance(); | ||
| $keyName = $key->name; | ||
| if (empty($keyName)) { | ||
| $keyName = $property->name; | ||
| } | ||
|
|
||
| $value = self::resolveValue($data, $keyName); | ||
|
|
||
| if ($value === self::missing()) { | ||
| if ($key->required) { | ||
| throw new Load("Missing required key: {$keyName}"); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| $expectedType = $property->getType(); | ||
| if ($expectedType === null || !method_exists($expectedType, 'getName')) { | ||
| throw new Load("Property {$property->name} is missing a type."); | ||
| } | ||
|
|
||
| $expectedClass = $expectedType->getName(); | ||
|
|
||
| if (!($value instanceof $expectedClass)) { | ||
| throw new Load("Invalid value for {$keyName}: Must be instance of {$expectedClass}."); | ||
| } | ||
|
|
||
| $propertyName = $property->name; | ||
| $instance->$propertyName = $value; | ||
| } | ||
|
|
||
| if (!$attributeFound) { | ||
| throw new Load("Property {$property->name} is missing attribute syntax."); | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Non-public config properties throw raw Error
load() iterates $reflection->getProperties() with no visibility filter (packages/config/src/Config.php:71), so protected and private properties are processed. A non-public property without an attribute fails with the misleading "missing attribute syntax" Load, and one with a #[Key] attribute reaches $instance->$propertyName = $value (packages/config/src/Config.php:100), which executes in Config's scope and throws an uncaught Error: Cannot access private property instead of Load. A schema author using an internal cached field gets a fatal, not a loader exception.
📋 Prompt for AI Agents
In packages/config/src/Config.php around line 71, change $reflection->getProperties() to $reflection->getProperties(\ReflectionProperty::IS_PUBLIC) so only public properties are considered. Optionally add an explicit check that rejects non-public properties with a descriptive Load exception (e.g. "Property X must be public") so schema authors get a clear loader error instead of an uncaught Error or the misleading "missing attribute syntax" message.
There was a problem hiding this comment.
This comes from utopia-php/config 2.0.8 as released: the absorb imports the mirror unchanged apart from the path move, restoring the registry, and Pint formatting. The RFC keeps API and behaviour changes out of absorb PRs, so it is tracked for a follow-up against packages/config (#13828) and not changed here.
There was a problem hiding this comment.
The user is claiming this is intentionally deferred to a follow-up PR (#13828) rather than fixed here. Looking at the current diff, $reflection->getProperties() on line 71 is unchanged — no visibility filter (ReflectionProperty::IS_PUBLIC) has been added, and no explicit non-public property check has been introduced. The issue remains present in this PR as submitted.
There was a problem hiding this comment.
The fix is claimed to have landed in #14235 (commit a792823), but that change is not visible in the current PR diff — the candidate file diff for packages/config/src/Config.php still shows $reflection->getProperties() on line 71 with no visibility filter and no explicit non-public property guard. Since this PR's code is unchanged from the original finding, the issue remains unresolved here, even if a separate PR addresses it downstream.
|
|
||
| $expectedType = $property->getType(); | ||
| if ($expectedType === null) { | ||
| throw new Load("Property {$property->name} is missing a type."); | ||
| } | ||
|
|
There was a problem hiding this comment.
🟡 bug · medium
Optional missing keys leave typed properties uninitialized
When an optional key is absent, load() hits continue (packages/config/src/Config.php:92) and leaves the property untouched. For a typed non-nullable property declared without a default (exactly the pattern in the library's own TestConfig fixtures), the loaded object is invalid: any later read throws Error: Typed property ... must not be accessed before initialization, a fatal outside the Load contract. Callers cannot distinguish "key absent" from "key loaded" and crash at first access.
📋 Prompt for AI Agents
In packages/config/src/Config.php at the optional-missing branch (lines 88-93), before continue, inspect the property: if the property is non-nullable typed and $property->isInitialized($instance) is false with no default value, throw a Load exception telling the schema author that an optional key's non-nullable typed property must declare a default. This prevents a later uninitialized-property Error on first access of the loaded object.
There was a problem hiding this comment.
This comes from utopia-php/config 2.0.8 as released: the absorb imports the mirror unchanged apart from the path move, restoring the registry, and Pint formatting. The RFC keeps API and behaviour changes out of absorb PRs, so it is tracked for a follow-up against packages/config (#13828) and not changed here.
There was a problem hiding this comment.
The user's reply is a maintenance/process explanation, not a fix claim. Looking at the full diff, the issue remains unaddressed: both continue branches (for Key around line 92 and for ConfigKey around line 128) still skip optional missing keys without checking whether the property is a non-nullable typed property lacking a default. The TestConfig fixture confirms the risk — properties like public string $phpKey have no default, are optional (required: false), and will be left uninitialized when their key is absent from the config source. A read of such a property will throw Error: Typed property must not be accessed before initialization. No guard was added in this PR.
There was a problem hiding this comment.
Fixed in #14235 (a792823). An absent optional key keeps the declared default. Without one, a nullable property becomes null and any other property raises Load, for both #[Key] and #[ConfigKey]. The README now states this. Covered by testAbsentOptionalKeyLeavesAUsableObject and testAbsentOptionalKeyWithoutDefaultThrowsLoad.
There was a problem hiding this comment.
The fix claimed in #14235 (a792823) is not visible in the diff evidence shown here — the current PR diff for packages/config/src/Config.php still contains the original unguarded 'continue' branches for both '#[Key]' and '#[ConfigKey]' when an optional key is absent, with no check for uninitialized non-nullable typed properties. Since the fix reportedly landed in a separate PR (#14235) rather than this one, I cannot verify it in the available evidence. The finding remains unresolved in this PR's diff.
| } | ||
|
|
||
| try { | ||
| $contents = include $tempPath; |
There was a problem hiding this comment.
🟡 bug · medium
PHP parser echoes tag-less config to output
Parser\PHP writes the contents to a temp file and includes it (packages/config/src/Parser/PHP.php:32) without any check for a PHP open tag. A config file accidentally saved without <?php has its raw text emitted as output (CLI/HTTP response pollution) while the include returns 1, so parsing "fails correctly" via the must-return-an-array branch — and the new testPHPParseExceptionMissingStart encodes this implementation accident rather than a real missing-start-tag rule. A future refactor of the return path can silently change what the test verifies.
📋 Prompt for AI Agents
In packages/config/src/Parser/PHP.php, add an explicit check in parse() that the contents begin with the PHP open tag (<?php) and throw a Parse exception otherwise, before writing the temp file. Then in packages/config/tests/Parser/PHPTest.php testPHPParseExceptionMissingStart (lines 141-145), keep the Parse expectation and add an assertion that no output was produced during parse (wrap the call in ob_start/ob_get_clean) so the test no longer depends on the incidental include-return-value behavior.
There was a problem hiding this comment.
This comes from utopia-php/config 2.0.8 as released: the absorb imports the mirror unchanged apart from the path move, restoring the registry, and Pint formatting. The RFC keeps API and behaviour changes out of absorb PRs, so it is tracked for a follow-up against packages/config (#13828) and not changed here.
There was a problem hiding this comment.
The user has explained this is an absorb PR that intentionally keeps the upstream utopia-php/config 2.0.8 code unchanged, with the fix deferred to a follow-up (#13828). Looking at the current diff for packages/config/src/Parser/PHP.php, the fix is not present — there is still no <?php open-tag check before writing the temp file, and the output-pollution risk remains in this PR. Since the fix has not landed here, I cannot resolve this finding based on a future PR's intent.
There was a problem hiding this comment.
The fix referenced in #14235 (commit 5a12875) is not present in the current diff shown for this PR — 'packages/config/src/Parser/PHP.php' still has no open-tag check before writing the temp file, and 'packages/config/tests/Parser/PHPTest.php' shows 'testPHPParseExceptionMissingStart' without the ob_start/ob_get_clean output assertion. Since the fix landed in a separate PR rather than here, I cannot resolve this finding against the evidence in this diff.
| $hash = strpos($raw, '#'); | ||
| if ($hash !== false) { | ||
| $raw = substr($raw, 0, $hash); | ||
| } | ||
|
|
||
| return trim($raw); |
There was a problem hiding this comment.
🟡 bug · medium
Dotenv truncates values at any #, mis-keys export
Parser\Dotenv::parseValue() strips everything from the first # of an unquoted value (packages/config/src/Parser/Dotenv.php:54-59), so a value like pa#ss silently becomes pa — mainstream dotenv implementations treat # as a comment only when preceded by whitespace, so URL=https://x.com/a#b and hashed secrets are corrupted. Separately, an export KEY=val line is stored under the key export KEY (no prefix handling in parse()), diverging silently from real dotenv files. Both feed function env variables through the VCS detection endpoints.
📋 Prompt for AI Agents
In packages/config/src/Parser/Dotenv.php parseValue() (lines 47-59), change the unquoted branch so the inline comment starts only at a # preceded by whitespace, preserving values like URL=https://x.com/a#b and PASSWORD=pa#ss. In parse() around line 139, strip a leading export prefix from $parts[0] before the $name = trim($parts[0]) assignment so export KEY=val stores key KEY like standard dotenv implementations.
There was a problem hiding this comment.
This comes from utopia-php/config 2.0.8 as released: the absorb imports the mirror unchanged apart from the path move, restoring the registry, and Pint formatting. The RFC keeps API and behaviour changes out of absorb PRs, so it is tracked for a follow-up against packages/config (#13828) and not changed here. The 1.x adapter Appwrite used before also cut values at the first # and kept export KEY as the key, so env detection behaves as it did on main.
There was a problem hiding this comment.
The user's reply is a deferral, not a fix claim — they acknowledge the bugs exist but explain this PR intentionally preserves the existing broken behavior for compatibility, with fixes tracked separately. Looking at the current diff, both issues remain unresolved in the code:
- 'parseValue()' still uses 'strpos($raw, "#")' without any whitespace check, so 'pa#ss' is still truncated to 'pa'.
- 'parse()' still does '$name = trim($parts[0])' with no 'export ' prefix stripping.
Since the fix is explicitly deferred to a follow-up PR and is not present in this diff, I cannot resolve this finding.
There was a problem hiding this comment.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Parser\Dotenv maps a literal null to PHP null, and the previous adapter returned the string. Detection suggests the value the file holds, so return 'null' rather than an empty string.
Summary
Moves
utopia-php/configintopackages/config, following the playbook inrfc/monorepo.md(#13828). Appwrite was onconfig 1.0.0, the static key/value registry. 2.x replaced that registry with a typedSource+Parserloader, so every consumer (Appwrite, Cloud, Edge, open-runtimes/executor) stayed on 1.x or 0.2. To close the gap,Configgets the registry back in 2.x. Call sites keepUtopia\Config\Config, and this supersedes #14224, which moved the registry intoAppwrite\Configinstead.Four commits plus the subtree merge:
Add 'packages/config/' from commit 'bdc39bc…': subtree import of the mirror with its full history. The mirror head is the2.0.8release, and its tree matchespackages/configinutopia-php/monorepo.chore(config): mirror plumbing:mirror.ymland the README banner now point here. The mirror's ruleset is normalised so the split app can bypass it.feat(config): restore the static registry on ConfigConfiggets$params,setParam()andgetParam()back, with the 1.x behaviour: dotted keys walk nested arrays, and an absent ornullkey returns the default. This is additive, so it releases asconfig/2.1.0.load()stays 2.x's typed loader. Its name collides with 1.x'sload($key, $path, $adapter), so registry users store values withsetParam()instead.tests/RegistryTest.php, plus a README section.src/Config/*→src/, tests →Utopia\Config\Tests\, a standalonerector.php, andphpstan.neonat level max with a baseline for the 123 findings the package arrived with (8 insrc, 115 in the parser tests). The baseline is listed for phase 8.ConfigTestnow sets the two_UTOPIA_KEY*variables itself, because the rootpackagessuite doesn't read the package'sphpunit.xml. OtherwisetestVariableSourceerrors there.src/is unchanged apart from the path move, the registry and Pint brace placement.refactor: load config from packages/replaceentries are added,"utopia-php/config": "1.*"is dropped, and the lock loses onlyutopia-php/config 1.0.0.app/init/configs.php: the 45Config::load($key, $path, new PHP())calls becomeConfig::setParam($key, include $path). 2.x'sParser\PHPincludes a temporary copy of the file, which would break the config files that use__DIR__. The old PHP adapter was a plainincludeanyway.Detections/Create,Repositories/XList) moves fromAdapters\DotenvtoParser\Dotenv. Behaviour changes there:#inside quotes is kept.=now rejects that file, which is skipped silently as before.nullbecomes PHPnull. The endpoints return it as"null", as before (999c0d1).rfc/monorepo.md: the Version gaps row is updated, open question 2 is resolved, and the baseline is listed.Plus
docs(config): strip trailing whitespace from the READMEandfix(vcs): keep a literal null in detected .env values(review).Tests
bin/monorepo test config: 75 tests / 257 assertions.packagessuite filtered toUtopia\Config, inappwrite/base:2.1.0: 75 tests pass.unitsuite inappwrite/base:2.1.0with.env: 1397 tests pass.app/init/constants.php+app/init/configs.phpregisters all 45 keys (platformresolves with 18 keys).VCSGiteaConsoleClientTest::testDetectionReadsVariablesFromDotenvcovers env detection through the parser switch: an inline comment, a quoted#, andKEY=null→"null". Nothing covered detected variables before. It runs in CI'sVCSGiteajob.bin/monorepo check config,bin/monorepo validate,composer lint,composer refactor:checkandcomposer analyzeall pass.bin/monorepo split config --dry-run:713e163.git diff --checkis clean apart from whitespace-only lines inside the parser tests' heredoc fixtures, which are deliberate.Merge and follow-up
Merge with a merge commit. A squash drops the
git-subtree-*annotation and orphans the package from its mirror.After merge:
Splitpushes toutopia-php/config, thenbin/monorepo release config 2.1.0.packages/configfromutopia-php/monorepo.server-cebump that picks this up has to rewrite its ownConfig::load($key, $path, $adapter)calls and anyAdapters\*/Exceptions\*imports in the same way. ItsConfig::getParam()/setParam()call sites are unaffected.^2.1whenever convenient. 0.2 stays on Packagist.Parser\PHPwithout an open tag, Dotenv#andexporthandling, two tests using mismatched keys, README examples) go to a follow-up againstpackages/config.Related: #13828
Related: #13828