yii1x / validator
validator
Requires
- php: ^8.3
- psr/http-message: ^2.0
Requires (Dev)
- phpunit/phpunit: ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-21 13:45:41 UTC
README
Yii 1.1 validation, extracted and modernized for PHP 8.3+.
Familiar validators. Zero framework lock-in.
What is it?
This package is the validation component from Yii 1.1, extracted and refactored to run on PHP 8.3+ without requiring the full Yii framework.
- ✅ Same validator behavior you know from Yii 1
- ✅ PHP 8 types and strict typing
- ✅ No
CModel, noYii::app(), no global state - ✅ Validates any plain
object - ✅ File uploads use PSR-7
UploadedFileInterface
Full reference of validators and options: docs/rules.md. Extending the validator (custom rule factories, DI): docs/extending.md.
Requirements
- PHP ≥ 8.3
psr/http-message(used by thefilevalidator)- Optional:
ext-intl— forvalidateIDNin theemailandurlvalidatorsext-mbstring— for multibyte-awarelengthvalidation
Installation
composer require yii1x/validator
Usage
<?php use Yii1x\Validator\Validator; $model = new class { public string $name = ''; public string $email = 'not-an-email'; }; $validator = new Validator($model, [ ['name', 'required'], ['email', 'email'], ]); if ($validator->validate()) { echo 'Valid!'; } else { print_r($validator->getErrors()); }
Scenarios, conditional rules, inline validators, the full rule list and every option are documented in docs/rules.md.
Testing
Requires Docker Compose. No database is needed — the tests are pure unit tests.
# Build the image and run the whole suite docker compose build docker compose run --rm php # Run a subset docker compose run --rm php php vendor/bin/phpunit --filter When
Tests run automatically on GitHub Actions for every push and pull request to master — see .github/workflows/ci.yaml.
Migration from Yii 1
⚠️ This package is a standalone port, not a drop-in replacement. Some behavior differs from the original Yii 1.1 validators (date formats, file handling, attribute labels, and more).
Before upgrading a legacy codebase, read docs/migration-from-yii1.md.
License
Released under the BSD-3-Clause License.
Based on Yii 1.1 by Yii Software LLC (BSD-3-Clause); portions copyright (c) 2025 Galtsev Timofey.