Repository navigation
refactor(validators)!: move the base class into Utopia\Validator - #14263
Conversation
A package that moves to a sibling's unreleased major cannot install from Packagist, so check failed on it before analysis started. check now takes --linked like test, both going through one install() helper, and CI passes it to dependents of changed packages as it already did for test. validate also accepts a singular namespace for a plural package name (validators -> Utopia\Validator\), and validators leaves BARE.
Utopia\Validator becomes Utopia\Validator\Validator and Utopia\PHPStan\DisallowAssertEqualsExtension becomes Utopia\Validator\PHPStan\DisallowAssertEqualsExtension, so the package declares the single Utopia\Validator\ prefix (step B). src/Validator/* moves up to src/. compat.php aliases the old names until the next major: the base class up front, since PHP never autoloads a name while checking a declared type; the PHPStan extension lazily, since installs without PHPStan cannot load it.
Appwrite and every sibling package that names the base class move to the new name. Siblings that use it require validators ^2.0 (cli and platform used it without declaring the dependency). console, which only uses the subclasses, accepts ^1.0 || ^2.0; audit keeps ^1.0 because the database release it requires pins validators ^1.0. The root autoload maps Utopia\Validator\ to packages/validators/src, loads compat.php, and keeps only console under the bare Utopia\ prefix. Refs #13828
bin/monorepo check and test --linked write composer.linked.json and its lock into the package directory; they are build output, not sources.
|
Review complete. 🟠 1 high · 🟡 2 medium 💬 Inline comments (1)
📍 Findings outside the diff (2) — 🟠 1 high · 🟡 1 medium — defects on lines GitHub can't attach comments to🟠 High — Bump The PR bumps 🟡 Medium — The The change moves the validators package to a
The compat shim and import sweep look correct; the flagged issues are dependency-constraint and tooling gaps that should be fixed before merge. Reviewed commit: 5dff0d3 |
🟢 Tier S · Ready to merge
The PR moves the validators and console base classes into package-specific namespaces while preserving legacy names through compatibility shims, and updates Appwrite and sibling consumers, package dependencies, tests, and PHPStan baselines. It also updates monorepo autoloading, namespace validation, linked dependency checks, and the RFC documentation for the migration. Latest changes: The newest commits update the GraphQL and SDK specification unit tests to import the validator base class from its new namespace.
📂 Walkthrough · 5
Reviewed the commits since |
There was a problem hiding this comment.
This PR migrates the utopia-php/validators package to a new Utopia\Validator\ namespace (v2.0) with a class_alias compatibility shim, rewrites consumers across packages/ and src/, and refactors bin/monorepo to share a --linked composer install path between check and test.
Key findings
- 🟠 Bump
packages/auditvalidators constraint to ^2.0 — composer.json - 🟡 CLI package keeps PHP 7.4 floor against validators v2 — composer.json:28
- 🟡
check --linkedsilently no-ops whenvendor/exists — monorepo:934
console took step B in #14261, so validators is the second to land: the root autoload drops the bare Utopia\ prefix, BARE is empty, both compat shims load through files, and console's Command imports the new validator name and requires validators ^2.0.
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)
|
check skipped install() whenever packages/<name>/vendor was present, so --linked silently analysed against whatever an earlier run installed. A linked run now always resolves, and drops the linked lock and the installed sibling copies first: a path package keeps its reference across uncommitted edits, so Composer would otherwise keep the stale copy.
cli requires utopia-php/validators ^2.0, which needs PHP 8.5, so its declared >=7.4 floor promised installs that cannot resolve. Raising it lets Rector's PHP 8.5 set apply (str_starts_with, a typed closure), which moves one baseline entry.
|
On tenki's summary item "Bump
The bump to |
|
@hansi-codes review |
|
Already reviewed 7afdb72. No new commits since then, so I didn't post another review. |
FormatTest and BuilderTest arrived from main after the rename and still imported the bare name, which only resolves through the compat shim.
Summary
This is phase 6 step B for
validators(#13828,rfc/monorepo.md). The package kept its base class at the bareUtopia\root, so it was one of the two packages still declared under the sharedUtopia\prefix. It now declares the singleUtopia\Validator\prefix:Utopia\Validator(base class)Utopia\Validator\ValidatorUtopia\PHPStan\DisallowAssertEqualsExtensionUtopia\Validator\PHPStan\DisallowAssertEqualsExtensionEvery other class (
Utopia\Validator\Text,…\JSON\FCMand so on) keeps its name.src/Validator/*moves up tosrc/.Shim
packages/validators/src/compat.phpis autoloaded throughfiles.bin/monorepo autoloadcopies it into the root, the same way client's 0.5 shim worked.Utopia\Validatoris aliased up front and guarded. PHP never autoloads a name while checking a declared type, so code typed against or extending the old name needs the alias to exist before it runs. The guard is there because a process can load the file through two autoloaders (a monorepo's root and the package's own).--no-devinstall. PHPStan resolves configured classes by name, so the lazy alias covers aphpstan.neonthat still lists it. Only this package's ownphpstan.neonused it, and a search of appwrite, appwrite-labs, open-runtimes and utopia-php found no other user.Call sites
src/app/tests/packages/validators(move, shim, tests)cli3,config4,dns6,domains5,emails8,http2,platform3,queue2,servers3,storage8utopia-php/validators: ^2.0.cliandplatformused it without declaring the dependency, so they gain the requirement.console(moved by refactor(console)!: move Console and Command into Utopia\Console #14261) imports the base class inCommandand requires^2.0.auditstays on^1.0. Theutopia-php/databasereleases it requires pin validators^1.0, so^2.0could not resolve for it. It only uses subclass names, which exist in both majors.cli,platform) name the base class and are updated to match. The validators baseline keeps its 38 entries / 75 findings, with paths and names moved.utopia-php/database7.4.1 (17 files extend or importUtopia\Validator) works through the alias:Utopia\Database\Validator\Indexresolves with parentUtopia\Validator\Validator.Tooling
The siblings now need a validators major that isn't on Packagist yet, and CI's per-package
checkresolved dependencies from Packagist. So:check --linked:bin/monorepo checktakes--linked, liketest. Both go through oneinstall()helper.ci.ymlpasses--linkedtocheckfor dependents of changed packages, as it already did fortest.validateaccepts a singular namespace for a plural package name through aSEGMENTSmap (validators→Validator; namespaces are singular).consoletook step B in refactor(console)!: move Console and Command into Utopia\Console #14261, so this PR is the second to land.BAREis now empty, and the root autoload no longer declares the bareUtopia\prefix. Bothcompat.phpshims load throughfiles..gitignoreignores thecomposer.linked.json/.lockfiles that linked installs write. They had been easy to commit by accident.Release plan
Cut
bin/monorepo release validators 2.0.0after this merges. The latest on Packagist is 1.0.1, and the rename is a major per the RFC, even though the shim keeps old names working.What consumers see:
server-ce: nothing changes. Cloud's ownuse Utopia\Validator;imports keep working through the shim until it moves to the new name.validators ^2.0. Release validators 2.0.0 before or alongside them.database/migration: these require^1.0. Appwrite's rootreplacealready satisfies that. Their absorb (Absorb database, mongo and migration into packages/ (wave 6) #14255) moves them onto the new name.Tests
packages/validators/tests/CompatTest.php:extends \Utopia\Validatoris aUtopia\Validator\Validator;\Utopia\Validatoraccepts a newText, run in a separate process so no earlier test registers the alias first;compat.phpemptied, all four fail: 2 errors and 2 failures, includingTypeError … must be of type Utopia\Validator, Utopia\Validator\Text given.bin/monorepo test validators: 189 tests, 1091 assertions.bin/monorepo checkpasses, with--linked, forvalidators,cli,config,dns,domains,emails,http,platform,queue,servers,storage,auditandconsole.bin/monorepo test --linkedpasses forconfig,dns,domains,emails,storage,audit,consoleandcli. The Swoole-based siblings (http,platform,queue,servers) are left to CI, because Swoole segfaults on the macOS host.bin/monorepo validate,composer lint,composer refactor:checkandcomposer analyzepass.unitsuite inappwrite/base:2.1.0(after merging main): 1428 tests pass.packagessuite inappwrite/base:2.1.0(after merging main): 9439 tests. The only errors are 5 inagents'DiffCheckTest("not a git repository": this worktree's.gitfile points outside the container mount), and there is onenatswarning. Neither touches validators.Related: #13828