Download the PHP package sujal/validation without Composer
On this page you can find all versions of the php package sujal/validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sujal/validation
More information about sujal/validation
Files in sujal/validation
Package validation
Short Description A small, object-oriented PHP validation library built around reusable Rule classes.
License MIT
Informations about the package validation
Validation
A PHP validation library built around reusable Rule classes.
You describe valid data with an immutable Schema of Field objects. Each check is a Rule class. A ValidationEngine runs the schema.
Built around SOLID boundaries — not a pile of if statements.
- PHP 8.2+
- No framework required
- MIT licensed
Install
Inside this repository:
Quick start
Flow in plain English:
- Build a
SchemafromFielddefinitions - Hand input + schema to
Validator::check(...) - Read
passed()/errors()/validated()
Why this shape (SOLID)
| Principle | How this library uses it |
|---|---|
| Single responsibility | Schema describes, ValidationEngine runs, MessageFormatter writes messages, DataReader reads paths |
| Open/closed | New rules are new classes — the engine does not change |
| Liskov | Any Rule is interchangeable; markers like AllowsNull extend behaviour safely |
| Interface segregation | Small contracts: Rule, DataReader, MessageCatalog, FormatsMessages |
| Dependency inversion | The engine depends on interfaces, not concrete helpers |
Fields and schemas are immutable. Calling ->bail() returns a new field — no hidden “current field” state.
A fuller example
Reuse schemas
Schemas are plain values. Merge the pieces you need:
Nested data and wildcards
Dotted paths read nested arrays:
Wildcards validate each item in a list:
Nullable and Sometimes
Labels and custom messages
Placeholders:
:attribute→ label or humanized field name- rule-specific ones like
:min,:max,:other
Reading errors
Throw instead of checking:
Optional fields
Without Required, blank values skip most rules:
Conditional required
Nested other-fields work too: new RequiredIf('account.type', 'business').
One-off custom checks
Write your own rule
Use marker interfaces when the engine must treat the rule specially:
ImplicitRule— always run, even if blank (Required)AllowsNull— skip remaining rules when value isnullValidatesWhenPresent— skip the field when the key is missing
Swap dependencies
Built-in rules
| Rule | What it checks |
|---|---|
Required |
Present and not blank |
RequiredIf |
Required when another field matches |
Nullable |
Allow null; skip other rules when null |
Sometimes |
Only validate if the key exists |
Email |
Email shape |
Integer / Numeric |
Numbers |
Str / Arr / Boolean |
Types |
Min / Max / Between / Length |
Size |
In / Regex / Url |
Format / allow-list |
Same / Confirmed |
Field matches |
Callback |
Your closure |
Import from Sujal\Validation\Rules.
Run the tests
License
Open source under the MIT License.