utopia-php / validators
A lightweight collection of reusable validators for Utopia projects
Installs: 1 801
Dependents: 6
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/utopia-php/validators
Requires
- php: >=8.1
Requires (Dev)
- ext-xdebug: *
- laravel/pint: ^1.2
- phpstan/phpstan: 1.*
- phpunit/phpunit: ^9.5.25
README
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 rule
- getDescription(): string– human readable rule summary
- getType(): 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 helpers
- ArrayList,- Assoc,- Nullable,- WhiteList,- Wildcard
- Boolean,- Integer,- FloatValidator,- Numeric,- Range
- Domain,- Host,- Hostname,- IP,- URL
- HexColor,- 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.