Add validation rules, lazy properties, and readonly properties#78
Merged
dereuromark merged 2 commits intomasterfrom Feb 8, 2026
Merged
Add validation rules, lazy properties, and readonly properties#78dereuromark merged 2 commits intomasterfrom
dereuromark merged 2 commits intomasterfrom
Conversation
Features:
- Validation rules: minLength, maxLength, min, max, pattern for field constraints
- Lazy properties: defer DTO/collection hydration until first getter access
- Readonly properties: public readonly with reconstruct-from-array for with*() methods
Config API:
- Field::string('name')->minLength(2)->maxLength(50)
- Field::int('age')->min(0)->max(150)
- Field::string('email')->pattern('/regex/')
- Field::dto('nested', 'Other')->asLazy()
- Dto::create('X')->readonlyProperties()
Changes:
- FieldBuilder: validation rule methods and lazy flag
- DtoBuilder: readonlyProperties() method (implies immutable)
- Builder/FieldCompletor: new field defaults and metadata keys
- Dto.php: validation rules in validate(), $_lazyData for lazy fields
- Templates: readonly property declarations, lazy getters, reconstruct-from-array with*() methods
- Tests: ValidationTest, LazyTest, ReadonlyTest + config builder tests
- Docs: updated ConfigBuilder.md and Validation.md
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #78 +/- ##
============================================
+ Coverage 82.56% 82.93% +0.37%
- Complexity 1333 1375 +42
============================================
Files 40 40
Lines 3252 3323 +71
============================================
+ Hits 2685 2756 +71
Misses 567 567 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- dto.xsd: add minLength, maxLength, min, max, pattern, lazy field attributes and readonlyProperties DTO attribute - dto.schema.json: add same fields for YAML/NEON validation - XmlEngine: cast lazy/readonlyProperties as bool, minLength/maxLength as int, min/max as numeric
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds three new features to close competitive gaps with libraries like spatie/laravel-data and cuyz/valinor:
Validation Rules
Fields now support built-in validation constraints via the config builder:
Rules are checked during construction (both fast-path and runtime). Null fields skip validation. On failure, throws
InvalidArgumentExceptionwith descriptive message.Lazy Properties
DTO and collection fields can defer hydration until first getter access:
Raw array data is stored in
$_lazyDataduring construction. The getter hydrates on demand.toArray()returns raw data directly if not yet hydrated — avoiding unnecessary object creation for pass-through scenarios.Readonly Properties
DTOs can generate
public readonlyproperties for language-level immutability:Generates
public readonly ?string $hostinstead ofprotected ?string $host. Thewith*()methods use reconstruct-from-array to work around PHP's readonly limitations. Implies immutable.Changes
FieldBuilder: validation rule methods (minLength,maxLength,min,max,pattern) andasLazy()DtoBuilder:readonlyProperties()method (implies immutable)Builder/FieldCompletor: new field defaults and metadata keysDto.php: validation rules invalidate(),$_lazyDatafor lazy fieldswith*()methods