utopia-php/validators
A lightweight collection of reusable validators for Utopia projects
Maintainers
Requires
- php: >=8.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT f1ac4f08d6876daf117a1d9af53a4c7b752c2c0b
This package is auto-updated.
Last update: 2026-06-12 16:11:34 UTC
README
Important
This repository is a read-only mirror of the utopia-php monorepo. Development happens in packages/validators — please open issues and pull requests there.
Reusable validation building blocks for Utopia projects.
This package exposes a consistent API for common HTTP-oriented validation concerns such as input sanitisation, URL checks, IP validation, hostname filtering, lists enforcement, and more.
Installation
composer require utopia-php/validators
Usage
use Utopia\Validator\Text; use Utopia\Validator\Range; $username = new Text(20, min: 3); $age = new Range(min: 13, max: 120); if (! $username->isValid($input['username'])) { throw new InvalidArgumentException($username->getDescription()); } if (! $age->isValid($input['age'])) { throw new InvalidArgumentException($age->getDescription()); }
Validators expose a predictable contract:
isValid(mixed $value): bool– core validation rulegetDescription(): string– human readable rule summarygetType(): string– expected PHP type (string, integer, array, ...)isArray(): bool– hint whether the validator expects an array input
For advanced flows combine validators with Multiple, AnyOf, AllOf, NoneOf, or wrap checks with helpers such as Nullable.
Available Validators
AllOf,AnyOf,NoneOf,Multiple– composition helpersArrayList,Assoc,Nullable,WhiteList,WildcardBoolean,Integer,FloatValidator,Numeric,RangeDomain,Host,Hostname,IP,URLHexColor,JSON,Text
Development
Run the static analysis and test suites from the project root:
composer check
composer test
This project is released under the MIT License.
