Skip to content

refactor(validators)!: move the base class into Utopia\Validator - #14263

Merged
ChiragAgg5k merged 10 commits into
mainfrom
refactor/validators-namespace
Oct 8, 2026
Merged

ChiragAgg5k merged 10 commits into
mainfrom
refactor/validators-namespace

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Summary

This is phase 6 step B for validators (#13828, rfc/monorepo.md). The package kept its base class at the bare Utopia\ root, so it was one of the two packages still declared under the shared Utopia\ prefix. It now declares the single Utopia\Validator\ prefix:

Old name New name
Utopia\Validator (base class) Utopia\Validator\Validator
Utopia\PHPStan\DisallowAssertEqualsExtension Utopia\Validator\PHPStan\DisallowAssertEqualsExtension

Every other class (Utopia\Validator\Text, …\JSON\FCM and so on) keeps its name. src/Validator/* moves up to src/.

Shim

packages/validators/src/compat.php is autoloaded through files. bin/monorepo autoload copies it into the root, the same way client's 0.5 shim worked.

  • Utopia\Validator is 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).
  • The old PHPStan name is aliased lazily, from an autoloader that fires only for that exact name. The extension implements PHPStan interfaces, so aliasing it up front would fatal in a --no-dev install. PHPStan resolves configured classes by name, so the lazy alias covers a phpstan.neon that still lists it. Only this package's own phpstan.neon used it, and a search of appwrite, appwrite-labs, open-runtimes and utopia-php found no other user.

Call sites

Area Files
src/ 40
app/ 4
tests/ 1
packages/validators (move, shim, tests) 60
siblings: cli 3, config 4, dns 6, domains 5, emails 8, http 2, platform 3, queue 2, servers 3, storage 8 44
  • The ten siblings that name the base class now require utopia-php/validators: ^2.0. cli and platform used 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 in Command and requires ^2.0.
  • audit stays on ^1.0. The utopia-php/database releases it requires pin validators ^1.0, so ^2.0 could not resolve for it. It only uses subclass names, which exist in both majors.
  • Two sibling PHPStan baselines (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.
  • Vendored utopia-php/database 7.4.1 (17 files extend or import Utopia\Validator) works through the alias: Utopia\Database\Validator\Index resolves with parent Utopia\Validator\Validator.

Tooling

The siblings now need a validators major that isn't on Packagist yet, and CI's per-package check resolved dependencies from Packagist. So:

  • check --linked: bin/monorepo check takes --linked, like test. Both go through one install() helper. ci.yml passes --linked to check for dependents of changed packages, as it already did for test.
  • Namespace rule: validate accepts a singular namespace for a plural package name through a SEGMENTS map (validators → Validator; namespaces are singular).
  • BARE list: console took step B in refactor(console)!: move Console and Command into Utopia\Console #14261, so this PR is the second to land. BARE is now empty, and the root autoload no longer declares the bare Utopia\ prefix. Both compat.php shims load through files.
  • Ignore rule: the root .gitignore ignores the composer.linked.json / .lock files that linked installs write. They had been easy to commit by accident.

Release plan

Cut bin/monorepo release validators 2.0.0 after 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:

  • Appwrite, and Cloud through server-ce: nothing changes. Cloud's own use Utopia\Validator; imports keep working through the shim until it moves to the new name.
  • Edge, open-runtimes/executor, and anything on Packagist: they stay on 1.x until they take 2.0. On 2.0 the old names keep working through the shim.
  • Sibling releases: the next release of each sibling that moved requires validators ^2.0. Release validators 2.0.0 before or alongside them.
  • Vendored database / migration: these require ^1.0. Appwrite's root replace already satisfies that. Their absorb (Absorb database, mongo and migration into packages/ (wave 6) #14255) moves them onto the new name.
  • Dropping the shim: at validators 3.0, once Cloud, Edge, executor and the absorbed database/migration use the new names.

Tests

  • New packages/validators/tests/CompatTest.php:
    • the old base-class name resolves to the new class;
    • a validator written against extends \Utopia\Validator is a Utopia\Validator\Validator;
    • a consumer typed \Utopia\Validator accepts a new Text, run in a separate process so no earlier test registers the alias first;
    • the old PHPStan name resolves to the moved extension.
  • With compat.php emptied, all four fail: 2 errors and 2 failures, including TypeError … must be of type Utopia\Validator, Utopia\Validator\Text given.
  • bin/monorepo test validators: 189 tests, 1091 assertions.
  • bin/monorepo check passes, with --linked, for validators, cli, config, dns, domains, emails, http, platform, queue, servers, storage, audit and console.
  • bin/monorepo test --linked passes for config, dns, domains, emails, storage, audit, console and cli. 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:check and composer analyze pass.
  • Appwrite unit suite in appwrite/base:2.1.0 (after merging main): 1428 tests pass.
  • Root packages suite in appwrite/base:2.1.0 (after merging main): 9439 tests. The only errors are 5 in agents' DiffCheckTest ("not a git repository": this worktree's .git file points outside the container mount), and there is one nats warning. Neither touches validators.
  • No old name is left in code outside the shim and its tests.

Related: #13828

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.
@luxor-code-review

luxor-code-review Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review complete. 🟠 1 high · 🟡 2 medium

💬 Inline comments (1)

  • 🟡 CLI package keeps PHP 7.4 floor against validators v2 — composer.json:28
📍 Findings outside the diff (2) — 🟠 1 high · 🟡 1 medium — defects on lines GitHub can't attach comments to

🟠 High — Bump packages/audit validators constraint to ^2.0 · packages/audit/composer.json

The PR bumps utopia-php/validators to ^2.0 in packages/config, packages/dns, packages/domains, packages/emails, packages/http, packages/platform, packages/queue, packages/servers, packages/storage, and packages/cli, and allows ^1.0 || ^2.0 in packages/console — but packages/audit still requires ^1.0 (packages/audit/composer.json:36) while its source imports the new-namespace class Utopia\Validator\Hostname (packages/audit/src/Adapter/ClickHouse.php:24). All packages publish the same Composer package name utopia-php/validators, so any consumer installing utopia-php/audit alongside any bumped package hits an unsolvable version conflict, and a standalone install of utopia-php/audit resolving validators 1.x risks a class-not-found on the new-namespace import. Inside the monorepo the root autoloader masks both problems, which is why they only surface on published mirrors.


🟡 Medium — check --linked silently no-ops when vendor/ exists · monorepo:934–940 · unchanged line

// bin/monorepo
934	            if (!is_dir("{$directory}/vendor")) {
935	                [$code] = install($package, isset($options['linked']));
936	                if ($code !== 0) {
937	                    $failed[] = "{$package} (composer)";
938	                    continue;
939	                }
940	            }

The check case only calls install() — and only passes --linked to it — when packages/{$package}/vendor is absent (bin/monorepo:934-935), so a vendor tree from an earlier registry-resolved composer update is reused as-is. Analysis then runs against registry-resolved dependencies, exactly the stale-resolution mode --linked exists to avoid, and the returned environment prefix is discarded so later composer-driven steps cannot inherit it either. Users passing --linked on any previously installed tree get a silent no-op of the flag rather than an error or a re-resolution.


The change moves the validators package to a Utopia\Validator\Validator base class with a compat.php alias shim for the old namespace, updates every consumer import across the monorepo, and bumps sibling composer constraints to ^2.0 (console keeps a dual ^1.0 || ^2.0). The bin/monorepo script extracts a shared install() routine used by both check and test, with a new --linked flag wired into CI.

Files Change
packages/validators/* Namespace migration to Utopia\Validator\, compat shim, phpstan/baseline updates, rewritten sources and tests
composer.json, packages/*/composer.json Autoload rewiring and sibling constraint bumps to ^2.0
bin/monorepo, .github/workflows/ci.yml, .gitignore, rfc/monorepo.md Shared install() with --linked path-repo resolution, CI matrix passthrough
src/Appwrite/**, app/controllers/* Consumer imports updated from Utopia\Validator to Utopia\Validator\Validator

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

@ghost

ghost commented Oct 8, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

No issues were found in the incremental changes or the reviewed pull request.

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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 5
File Change
packages/validators/**, packages/console/** Move base classes into package-specific namespaces and provide compatibility shims for legacy names.
packages/{cli,config,dns,domains,emails,http,platform,queue,servers,storage}/** Update sibling validator references, dependency constraints, and affected PHPStan baselines.
app/**, src/**, tests/unit/** Update Appwrite imports and consumers to use the new validator base-class namespace.
bin/monorepo, composer.json, .github/workflows/ci.yml, .gitignore Update package autoloading and namespace validation, add linked dependency checks, and ignore generated linked Composer files.
rfc/monorepo.md Document the validators namespace migration and its completion.

Reviewed the commits since 927f3f7 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · See the inline comments. Summary

Comment thread bin/monorepo Resolved

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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/audit validators constraint to ^2.0 — composer.json
  • 🟡 CLI package keeps PHP 7.4 floor against validators v2 — composer.json:28
  • 🟡 check --linked silently no-ops when vendor/ exists — monorepo:934

Comment thread packages/cli/composer.json Resolved
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.
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → refactor/validators-namespace (after).

Metric Before After Change
🚀 Requests/sec 197.58 196.17 ⚪ -0.7%
⏱️ Latency P50 86.25 ms 89.02 ms ⚪ +3.2%
⏱️ Latency P95 211.28 ms 205.94 ms ⚪ -2.5%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 89.02 205.94 12,540 196.17 -5.34
Account 168.32 330.82 660 10.94 +21.87
TablesDB 86.42 165.93 6,820 108.65 +7.46
Storage 81.05 175.51 3,300 54.41 -7.53
Functions 126.1 243.54 1,760 29.77 -11.44

Top API waits (after)

API request Max wait (ms)
account.name.update 506.37
account.prefs.update 478.96
functions.delete 404.32
account.get 377.76
functions.variables.update 367.34

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.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

On tenki's summary item "Bump packages/audit validators constraint to ^2.0": audit stays on ^1.0 for now, on purpose.

  • audit only uses Utopia\Validator\Hostname, which exists in both 1.x and 2.x.
  • audit also requires utopia-php/database ^7, which is still vendored here, and every 7.x release pins validators ^1.0 or older. With ^2.0, audit cannot be installed on its own at all: I checked with a dry-run resolve.
  • ^1.0 || ^2.0 resolves on its own, but it breaks the linked CI run. --linked labels the local checkout with the newest line the constraint names (2.0.999), and database rejects that. With ^1.0, it is linked as 1.x and resolves: check audit --linked passes locally and Packages / audit passes in CI.

The bump to ^2.0 lands with wave 6 (#14255), once database lives in packages/ and requires validators ^2.0 itself. usage, which also uses Hostname without declaring validators, gets its declaration then too, for the same reason.

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost

ghost commented Oct 8, 2026

Copy link
Copy Markdown

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.
@ChiragAgg5k
ChiragAgg5k merged commit 5ebc928 into main Oct 8, 2026
105 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the refactor/validators-namespace branch October 8, 2026 14:17
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.

1 participant