Skip to content

Commit 79ed7f4

Browse files
committed
chore: resolve merge conflicts, keep local changes
2 parents db0ee89 + 807d48a commit 79ed7f4

44 files changed

Lines changed: 5067 additions & 89 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,37 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.1.0] - 2026-01-15
9+
### Added
10+
- **Reusable Rules** - Register field-agnostic validation patterns with `DataVerify::registerRules()`
11+
- **Validation Schemas** - Define complete validation structures with `DataVerify::registerSchema()`
12+
- Rules support 3 syntaxes: `->rule('ruleName')`, `->rule->ruleName`, `->rule->ruleName()`
13+
- Schemas support 3 syntaxes: `->schema('schemaName')`, `->schema->schemaName`, `->schema->schemaName()`
14+
- Schemas support conditional logic and rule composition
15+
- **Load from directory** - `DataVerify::loadRulesFrom()` and `DataVerify::loadSchemasFrom()` for file-based organization
16+
- **Auto-discovery from directory** - Load custom validation strategies automatically via `LazyValidationRegistry`
17+
- Example files for rules and schemas in `/examples` including batch registration and performance patterns
18+
19+
### Changed
20+
- **Deferred Conditional Evaluation** - Conditional validations now evaluate during `verify()` instead of at definition time for more intuitive rule composition
21+
22+
### Refactored
23+
- LazyValidationRegistry now auto-discovers validation directories without hardcoded configuration
24+
- Removed legacy `conditionalValidations` system in favor of unified `allValidations` structure
25+
- Enhanced OpenAPI documentation with Rules & Schemas sections
26+
27+
### Performance
28+
- Rules registration: 1.4μs P99 (20 rules: 20.6μs)
29+
- Schema registration: 4.6μs P99 (10 schemas: 45.9μs)
30+
- Rules application: 5.9μs P99 (comparable to inline)
31+
- Schema application: 7.7μs P99 (37% faster than manual!)
32+
- All validations remain <20μs P99
33+
34+
### Tests
35+
- Add 2 Unit Test Class for Rules & Schema
36+
- 616 tests, 1192 assertions, 0 failures
37+
- Mutation score: 84%
38+
839
## [1.0.5] - 2026-01-06
940
### Tests
1041
- Restructured test suite into Unit/Integration/Regression hierarchy

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ mutation:
1010
@vendor/bin/infection --threads=4
1111

1212
benchmark:
13+
sudo mv /etc/php/8.5/cli/conf.d/20-pcov.ini /etc/php/8.5/cli/conf.d/20-pcov.ini.bak
1314
@vendor/bin/phpbench run --report=default --warmup=2 --output=csv > benchmarks/bench_results.csv
15+
sudo mv /etc/php/8.5/cli/conf.d/20-pcov.ini.bak /etc/php/8.5/cli/conf.d/20-pcov.ini
1416

1517
p99:
1618
@cd benchmarks && php analyze_bench.php

README.md

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,36 @@ $dv->field('vat_number')
5555
->then->required->regex('/^FR\d{11}$/');
5656
```
5757

58-
**Custom strategies**
58+
**Reusable Rules & Schemas**
59+
```php
60+
// Register reusable validation rules
61+
DataVerify::registerRules('strongPassword')
62+
->minLength(12)
63+
->containsUpper
64+
->containsLower
65+
->containsSpecialCharacter;
66+
67+
// Apply to any field
68+
$dv->field('password')->rule('strongPassword');
69+
70+
// Register complete validation schemas
71+
DataVerify::registerSchema('userApi')
72+
->field('user')->required->object
73+
->subfield('email')->email
74+
->when('user.id', '!=', null)->then->required
75+
->subfield('password')->rule('strongPassword')
76+
->when('user.id', '!=', null)->then->required;
77+
78+
// Apply entire schema
79+
$dv = new DataVerify($data);
80+
$dv->schema('userApi');
81+
82+
if(!$dv->verify()){
83+
// Get Your Errors
84+
}
85+
```
86+
87+
**Custom validation strategies**
5988
```php
6089
class SiretStrategy extends ValidationStrategy {
6190
public function getName(): string { return 'siret'; }
@@ -217,38 +246,44 @@ $dv->addTranslations([
217246

218247
-**Zero dependencies** - Pure PHP 8.1+, no vendor bloat
219248
-**Fluent API** - Readable, chainable validations
220-
-**Extensible** - Custom strategies with auto-documentation
221-
-**Fast** - ~9μs simple validation, ~4.9MB memory ([benchmarks](docs/BENCHMARK.md))
249+
-**Reusable patterns** - Rules & Schemas for DRY validation with auto-documentation
250+
-**Extensible** - Custom validation strategies with auto-documentation
251+
-**Fast** - ~9.7μs simple validation, ~2MB memory ([benchmarks](docs/BENCHMARK.md))
222252
-**i18n ready** - Built-in translation support (EN, FR)
223253
-**Framework agnostic** - Works with WordPress, Laravel, Symfony, vanilla PHP
224-
-**Production tested** - 500+ tests, 83% mutation score
254+
-**Worker-mode ready** - Tested with FrankenPHP, stable memory over 3M+ requests
255+
-**Production tested** - 600+ tests, 84% mutation score
225256

226257
## Documentation
227258

228259
**Guides:**
260+
- [Rules & Schemas](docs/RULES_AND_SCHEMAS.md) - Reusable validation patterns
229261
- [Conditional Validation](docs/CONDITIONAL_VALIDATION.md) - `when/and/or/then` syntax
230262
- [Custom Strategies](docs/CUSTOM_STRATEGIES.md) - Extend with your own rules
231263
- [Internationalization](docs/INTERNATIONALIZATION.md) - Multi-language error messages
232264
- [Error Handling](docs/ERROR_HANDLING.md) - Working with validation errors
233265
- [Validation Rules](docs/VALIDATIONS.md) - All 30+ built-in rules
266+
- [Benchmarks](docs/BENCHMARK.md) - Performance metrics
234267

235268
**Examples:**
236269
- [API Request Validation](examples/api-request.php)
237270
- [Basic Usage](examples/basic.php)
238271
- [Conditional Validation](examples/conditional-validation.php)
239272
- [Custom Validation Rules](examples/custom-validation.php)
273+
- [Reusable Rules](examples/rules.php)
274+
- [Validation Schemas](examples/schema.php)
240275
- [Translation (PHP)](examples/translation-basic.php)
241276
- [Translation (YAML)](examples/translation-yaml.php)
242277

243278
## Performance
244279

245280
DataVerify is designed for production with predictable sub-millisecond performance:
246281
```
247-
Simple validation: ~8.7μs (99% < 9μs)
248-
Complex nested: ~16.4μs (99% < 18μs)
249-
Batch mode (100 fields): ~0.53ms
250-
Fail-fast (100 fields): ~0.23ms (2.3x faster)
251-
Memory usage: ~4.9MB (stable)
282+
Simple validation: ~9.7μs (99% < 10μs)
283+
Complex nested: ~19.1μs (99% < 20μs)
284+
Batch mode (100 fields): ~572.9μs
285+
Fail-fast (100 fields): ~256.1μs (2.2x faster)
286+
Memory usage: ~2MB (stable)
252287
```
253288

254289
**See:** [Full benchmarks](docs/BENCHMARK.md)
@@ -377,4 +412,4 @@ MIT License - see [LICENSE](LICENCE) file for details.
377412

378413
---
379414

380-
**Made with ❤️ by [Romain Feregotto](https://github.com/gravity-zero)**
415+
**Made with ❤️ by [Romain Feregotto](https://github.com/gravity-zero)**

docs/BENCHMARK.md

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,80 @@
11
## Performance
22

3-
DataVerify is designed for production use with predictable, sub-millisecond performance.
3+
**[← Back to Main Documentation](../README.md)**
4+
5+
**Navigation:** [Validations](VALIDATIONS.md) | [Conditional Validation](CONDITIONAL_VALIDATION.md) | [Rules & Schemas](RULES_AND_SCHEMAS.md) | [Custom Strategies](CUSTOM_STRATEGIES.md) | [Error Handling](ERROR_HANDLING.md) | [Internationalization](INTERNATIONALIZATION.md) | [Benchmarks](BENCHMARK.md)
46

57
### Run Benchmarks
68
```bash
79
make benchmark # Standard benchmarks
8-
make benchmark-stats # With P50/P95/P99 percentiles
10+
make p99 # With P50/P95/P99 percentiles
911
```
1012

1113
### Results (PHP 8.5.1 + OPcache)
1214

1315
**Core Operations** (P99):
14-
- Simple validation: **8.7μs** (99% < 9μs)
15-
- Complex nested: **16.4μs** (99% < 17μs)
16-
- Custom strategy: **11.2μs** (99% < 12μs)
16+
- Simple validation: **9.7μs**
17+
- Complex nested: **19.1μs**
18+
- Custom strategy: **14.2μs**
1719

1820
**Batch Processing:**
19-
- Batch mode (100 fields): **~0.53ms**
20-
- Fail-fast mode (100 fields): **~0.23ms****2.3x faster**
21+
- Batch mode (100 fields): **572.9μs**
22+
- Fail-fast mode (100 fields): **256.1μs**2x faster
2123

2224
**Conditional Validations** (P99):
23-
- Triggered: **8.5μs**
24-
- Not triggered: **5.7μs** ← Faster (validation skipped)
25-
- Failed + errors: **13μs** ← Most expensive (error rendering)
26-
- Complex AND/OR: **~6.1μs**
25+
- Triggered: **10.2μs**
26+
- Not triggered: **8.3μs** ← Faster (validation skipped)
27+
- Failed + errors: **16.2μs** ← Most expensive (error rendering)
28+
- Complex AND/OR: **7.8μs**
29+
- Deferred evaluation: **11.9μs**
30+
31+
**Custom Validation Strategies** (P99):
32+
- Custom strategy execution: **14.2μs**
33+
- Load from directory (bootstrap): **29.4μs**
34+
35+
**Rules & Schemas** (P99):
36+
- Rule registration: **1.4μs**
37+
- Rule application: **5.9μs**
38+
- Schema registration: **4.6μs**
39+
- Schema application: **7.7μs**
40+
- Schema vs manual: **7.7μs vs 12.3μs**
41+
- Schema with rules: **10.0μs**
42+
- Schema with conditionals: **9.4μs**
43+
44+
**Batch Loading:**
45+
- Load 20 rules: **20.6μs**
46+
- Load 10 schemas: **45.9μs**
47+
48+
**Translation:**
49+
- With translation: **17.3μs**
50+
- Without translation: **16.7μs**
51+
52+
**Memory:** ~2MB
2753

28-
**Translation Overhead:**
29-
- With translation: **14.6μs**
30-
- Without translation: **14.3μs**
31-
- **Overhead: ~2-3%** (negligible)
54+
### FrankenPHP Worker Mode
3255

33-
**Memory:** ~4.9MB (stable, no leaks)
56+
Tested for long-running process stability:
57+
58+
| Metric | Result |
59+
|--------|--------|
60+
| Requests | 3M+ |
61+
| Memory | 2MB stable (Δ0 after warmup) |
62+
| Throughput | ~3400 req/s (4 workers) |
63+
| Errors | 0 |
64+
65+
**Production-ready** for worker mode - no memory leaks detected.
3466

3567
**Key Insights:**
36-
-**99% of validations complete in <17μs** (sub-millisecond)
37-
-**Very low variance** - P99 tightly clustered around the mean
38-
-**Fail-fast mode 2.3x faster** when you need speed
39-
-**Conditional skip is fast** - unused validations add minimal overhead
40-
-**Static translator cache** eliminates file I/O overhead
68+
- ✅ 99% of validations complete in <20μs
69+
- ✅ Fail-fast mode is 2.2x faster than batch mode
70+
- ✅ Schemas are 37% faster than manual validation (7.7μs vs 12.3μs)
71+
- ✅ Translation overhead is minimal (~3.6%)
72+
- ✅ Batch loading is efficient: 1μs per rule, 4.6μs per schema
73+
74+
*Benchmarks: [PHPBench 1.4.3](https://github.com/phpbench/phpbench) • PHP 8.5.1 • OPcache enabled*
75+
76+
---
77+
78+
**Navigation:** [Validations](VALIDATIONS.md) | [Conditional Validation](CONDITIONAL_VALIDATION.md) | [Rules & Schemas](RULES_AND_SCHEMAS.md) | [Custom Strategies](CUSTOM_STRATEGIES.md) | [Error Handling](ERROR_HANDLING.md) | [Internationalization](INTERNATIONALIZATION.md) | [Benchmarks](BENCHMARK.md)
4179

42-
*Benchmarks: [PHPBench 1.4.3](https://github.com/phpbench/phpbench) • PHP 8.5.1 • OPcache enabled*
80+
**[← Back to Main Documentation](../README.md)**

docs/CONDITIONAL_VALIDATION.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Conditional Validation
22

3+
**[← Back to Main Documentation](../README.md)**
4+
5+
**Navigation:** [Validations](VALIDATIONS.md) | **Conditional Validation** | [Rules & Schemas](RULES_AND_SCHEMAS.md) | [Custom Strategies](CUSTOM_STRATEGIES.md) | [Error Handling](ERROR_HANDLING.md) | [Internationalization](INTERNATIONALIZATION.md) | [Benchmarks](BENCHMARK.md)
6+
7+
---
8+
39
DataVerify supports conditional validation where validation rules are only applied when specific conditions are met. Combine conditions using `and()` and `or()` operators.
410

511
## Table of Contents
@@ -475,6 +481,12 @@ $dv->field('vat_number')
475481
## See Also
476482

477483
- **[Validation Rules](VALIDATIONS.md)** - All available validation rules
484+
- **[Rules & Schemas](RULES_AND_SCHEMAS.md)** - Reusable validation patterns with conditionals
478485
- **[Error Handling](ERROR_HANDLING.md)** - Handle conditional validation errors
479486
- **[Custom Strategies](CUSTOM_STRATEGIES.md)** - Custom conditional logic
480-
- **[Internationalization](INTERNATIONALIZATION.md)** - Translate error messages
487+
488+
---
489+
490+
**Navigation:** [Validations](VALIDATIONS.md) | **Conditional Validation** | [Rules & Schemas](RULES_AND_SCHEMAS.md) | [Custom Strategies](CUSTOM_STRATEGIES.md) | [Error Handling](ERROR_HANDLING.md) | [Internationalization](INTERNATIONALIZATION.md) | [Benchmarks](BENCHMARK.md)
491+
492+
**[← Back to Main Documentation](../README.md)**

docs/CUSTOM_STRATEGIES.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Custom Validation Strategies
22

3+
**[← Back to Main Documentation](../README.md)**
4+
5+
**Navigation:** [Validations](VALIDATIONS.md) | [Conditional Validation](CONDITIONAL_VALIDATION.md) | [Rules & Schemas](RULES_AND_SCHEMAS.md) | **Custom Strategies**(CUSTOM_STRATEGIES.md) | [Error Handling](ERROR_HANDLING.md) | [Internationalization](INTERNATIONALIZATION.md) | [Benchmarks](BENCHMARK.md)
6+
7+
---
8+
39
Extend DataVerify with your own validation logic through custom strategies.
410

511
## Table of Contents
@@ -17,6 +23,11 @@ Extend DataVerify with your own validation logic through custom strategies.
1723

1824
## Quick Start
1925
```php
26+
27+
use Gravity\DataVerify;
28+
use Gravity\Interfaces\ValidationStrategyInterface;
29+
30+
2031
// 1. Create strategy
2132
// The #[ValidationRule] attribute enables auto-documentation generation and IDE stub creation (See IDE Autocompletion)
2233
#[ValidationRule(
@@ -441,4 +452,10 @@ $dv->registerStrategy(ValidationStrategyInterface $strategy): self
441452
- **[Validation Rules](VALIDATIONS.md)** - All built-in validation rules
442453
- **[Internationalization](INTERNATIONALIZATION.md)** - Add translations for custom strategies
443454
- **[Error Handling](ERROR_HANDLING.md)** - Custom error messages for strategies
444-
- **[Conditional Validation](CONDITIONAL_VALIDATION.md)** - Use strategies with conditions
455+
- **[Conditional Validation](CONDITIONAL_VALIDATION.md)** - Use strategies with conditions
456+
457+
---
458+
459+
**Navigation:** [Validations](VALIDATIONS.md) | [Conditional Validation](CONDITIONAL_VALIDATION.md) | [Rules & Schemas](RULES_AND_SCHEMAS.md) | [Custom Strategies](CUSTOM_STRATEGIES.md) | [Error Handling](ERROR_HANDLING.md) | [Internationalization](INTERNATIONALIZATION.md) | [Benchmarks](BENCHMARK.md)
460+
461+
**[← Back to Main Documentation](../README.md)**

docs/ERROR_HANDLING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Error Handling
22

3+
**[← Back to Main Documentation](../README.md)**
4+
5+
**Navigation:** [Validations](VALIDATIONS.md) | [Conditional Validation](CONDITIONAL_VALIDATION.md) | [Rules & Schemas](RULES_AND_SCHEMAS.md) | [Custom Strategies](CUSTOM_STRATEGIES.md) | **Error Handling**(ERROR_HANDLING.md) | [Internationalization](INTERNATIONALIZATION.md) | [Benchmarks](BENCHMARK.md)
6+
7+
---
8+
39
DataVerify provides flexible error retrieval with detailed information about validation failures.
410

511
## Table of Contents
@@ -394,3 +400,10 @@ if (!$dv->verify()) {
394400
- **[Internationalization](INTERNATIONALIZATION.md)** - Multi-language error messages
395401
- **[Validation Rules](VALIDATIONS.md)** - All available validation rules
396402
- **[Custom Strategies](CUSTOM_STRATEGIES.md)** - Error messages for custom validations
403+
404+
405+
---
406+
407+
**Navigation:** [Validations](VALIDATIONS.md) | [Conditional Validation](CONDITIONAL_VALIDATION.md) | [Rules & Schemas](RULES_AND_SCHEMAS.md) | [Custom Strategies](CUSTOM_STRATEGIES.md) | [Error Handling](ERROR_HANDLING.md) | [Internationalization](INTERNATIONALIZATION.md) | [Benchmarks](BENCHMARK.md)
408+
409+
**[← Back to Main Documentation](../README.md)**

docs/INTERNATIONALIZATION.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Internationalization (i18n)
22

3+
**[← Back to Main Documentation](../README.md)**
4+
5+
**Navigation:** [Validations](VALIDATIONS.md) | [Conditional Validation](CONDITIONAL_VALIDATION.md) | [Rules & Schemas](RULES_AND_SCHEMAS.md) | [Custom Strategies](CUSTOM_STRATEGIES.md) | [Error Handling](ERROR_HANDLING.md) | **Internationalization**(INTERNATIONALIZATION.md) | [Benchmarks](BENCHMARK.md)
6+
7+
---
8+
39
DataVerify includes a built-in translation system for validation error messages. Built-in languages (English, French) are automatically loaded - just set the locale.
410

511
## Table of Contents
@@ -403,3 +409,10 @@ class MyStrategy extends ValidationStrategy
403409
- **[Custom Strategies](CUSTOM_STRATEGIES.md)** - Parameter mapping for custom validations
404410
- **[Error Handling](ERROR_HANDLING.md)** - Working with translated errors
405411
- **[Validation Rules](VALIDATIONS.md)** - All validation rules
412+
413+
414+
---
415+
416+
**Navigation:** [Validations](VALIDATIONS.md) | [Conditional Validation](CONDITIONAL_VALIDATION.md) | [Rules & Schemas](RULES_AND_SCHEMAS.md) | [Custom Strategies](CUSTOM_STRATEGIES.md) | [Error Handling](ERROR_HANDLING.md) | [Internationalization](INTERNATIONALIZATION.md) | [Benchmarks](BENCHMARK.md)
417+
418+
**[← Back to Main Documentation](../README.md)**

0 commit comments

Comments
 (0)