You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**`FieldValidator`** - Abstract base class with unified validation interface and shared functionality
12
-
-**`ValidationException`** - Structured exception handling with comprehensive error collection
12
+
-**`ValidationException`** - Structured exception handling with aggregated error reporting
13
13
14
14
### Type-Specific Validators
15
15
-**`StringValidator`** - Format validation (email, URL, UUID with version variants, IP with version variants, hostname, domain, time, base64 with variants, hex), length constraints, pattern matching
@@ -29,14 +29,14 @@ A comprehensive, fluent validation library for PHP inspired by Valibot and Zod.
29
29
-**Static Logical Combinators** - `Validator::allOf()`, `Validator::anyOf()`, `Validator::not()` for complex rule composition and mixed-type validation
30
30
-**New `satisfies*` API** - Enhanced instance logical combinators (`satisfiesAny()`, `satisfiesAll()`, `satisfiesNone()`) with support for mixed validators/callables
31
31
-**Enum-Based Variant Flags** - Type-safe variant selection for IP addresses (`IpVersion`), Base64 encoding (`Base64Variant`), and UUID versions (`UuidVariant`) with consistent API pattern
32
-
-**Smart Null Handling** - Revolutionary null handling system where validations skip`null` unless `required()`, transformations always execute, and order is independent
32
+
-**Smart Null Handling** - Validations skip `null` unless `required()`. `transform()` runs on`null`, while `pipe()` and `nullifyEmpty()` skip `null` for type safety.
33
33
-**Form-Safe Coercion** - Empty strings convert to `null` (not dangerous `0`/`0.0`/`false`) for primitives, empty structures for objects/arrays
-**Type-Aware Transformations** - Revolutionary `transform()` and `pipe()` system with intelligent type context switching
36
-
-**Unified Pipeline Architecture** - Single conceptual pipeline with hybrid execution (error collection for validations, fail-fast for transformations)
36
+
-**Unified Pipeline Architecture** - Single conceptual pipeline with ordered execution and fail-fast behavior per field
37
37
-**Custom Validation** - Enhanced `satisfies()` method accepting `FieldValidator` instances or callables with optional error messages (all internal validators migrated from deprecated `addValidation()`)
Copy file name to clipboardExpand all lines: README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,22 +26,22 @@ Rather than reimplementing every possible transformation or validation rule, Lem
26
26
**Key Design Principles:**
27
27
28
28
-**Type-Safe Architecture**: Modern PHP 8.1+ enums provide IDE autocomplete, refactoring safety, and eliminate magic strings throughout the codebase
29
-
-**Smart Null Handling**: Validations skip `null` unless `required()`, transformations always execute, and method order is independent for intuitive behavior
29
+
-**Smart Null Handling**: Validations skip `null` unless `required()`. `transform()` runs on `null`, while `pipe()` and `nullifyEmpty()` skip `null`for type safety.
30
30
-**Form Safety First**: Empty strings coerce to `null` (not dangerous `0`/`false`) to prevent real-world issues like accidental zero bank balances
31
31
-**Fluent API with Execution Order Guarantee**: Validation rules read like natural language and execute in the exact order written -- `Validator::isString()->pipe('trim')->nullifyEmpty()->required()`
32
-
-**Comprehensive Error Collection**: All validation errors are collected, not just the first failure
32
+
-**Fail-Fast Per Field**: Each validator stops at the first failing rule, while schema validation still aggregates errors across fields
33
33
-**API-Friendly Error Format**: Flattened errors with field paths (`'_root'` for root-level, dot notation for nested) perfect for frontend consumption
34
34
-**Type-Aware Transformations**: Intelligent transformation system that maintains type context and handles coercion automatically
35
35
-**Extensible Architecture**: Generic transformation methods work with any PHP callable or external library
36
-
-**Strict Typing**: All files use `declare(strict_types=1);`, so scalar mismatches raise clear errors; opt into `coerce()` when you need form-friendly conversions.
36
+
-**Strict Typing**: All files use `declare(strict_types=1);`, keeping internal type hints strict; opt into `coerce()` when you need form-friendly conversions.
37
37
38
38
## Features
39
39
40
40
-**Type-safe architecture** - PHP 8.1+ enums with IDE autocomplete, refactoring safety, and zero magic strings
**Critical**: Methods execute in the **exact order written**. This is especially important when combining transformations with `required()`:
154
+
**Critical**: Pipeline steps execute in the **exact order written**. This matters for `pipe()`, `transform()`, and `nullifyEmpty()`. `required()` is a flag, so its position does not change execution order.
154
155
155
156
```php
156
-
// CORRECT: Trim → nullify → require (fails on empty input)
157
-
$requiredName = Validator::isString()
157
+
// Order matters for transformations
158
+
$trimThenNullify = Validator::isString()
158
159
->pipe('trim') // 1. Remove whitespace
159
-
->nullifyEmpty() // 2. Empty strings → null
160
-
->required('Name is required'); // 3. Reject null values
160
+
->nullifyEmpty(); // 2. Empty strings → null
161
161
162
-
$requiredName->validate(' '); // ❌ "Name is required" (correct!)
162
+
$trimThenNullify->validate(' '); // Returns: null
163
163
164
-
// ❌ DIFFERENT BEHAVIOR: Require → nullify (allows empty input)
165
-
$differentBehavior = Validator::isString()
166
-
->required('Name is required') // 1. Check if empty string is null (passes)
0 commit comments