LiteDto & SimpleDto
Data Helpers provides two DTO implementations, each optimized for different use cases:
- LiteDto - Maximum performance with minimal overhead
- SimpleDto - Full-featured with validation, type casting, and advanced features
Quick Overview
Section titled “Quick Overview”LiteDto
Section titled “LiteDto”LiteDto is designed for maximum performance when you need fast data transfer without validation or type casting.
use event4u\DataHelpers\LiteDto\LiteDto;
class UserDto extends LiteDto{    public function __construct(        public readonly string $name,        public readonly string $email,        public readonly int $age,    ) {}}
$user = UserDto::from(['name' => 'John', 'email' => 'john@example.com', 'age' => 30]);Best for:
- High-performance APIs
- Data transfer between layers
- Simple data structures
- When validation is handled elsewhere
SimpleDto
Section titled “SimpleDto”SimpleDto provides full validation and type casting with a rich feature set.
use event4u\DataHelpers\SimpleDto\SimpleDto;use event4u\DataHelpers\Attributes\Validation\Email;use event4u\DataHelpers\Attributes\Validation\Min;
class UserDto extends SimpleDto{    public function __construct(        public readonly string $name,
        #[Email]        public readonly string $email,
        #[Min(18)]        public readonly int $age,    ) {}}
$user = UserDto::from(['name' => 'John', 'email' => 'john@example.com', 'age' => 30]);Best for:
- Form validation
- API input validation
- Complex data structures
- When you need type casting (DateTime, Enum, etc.)
Performance & Feature Comparison
Section titled “Performance & Feature Comparison”| Feature | LiteDto #[UltraFast] | LiteDto | SimpleDto #[UltraFast] | SimpleDto | 
|---|---|---|---|---|
| Performance | ~0.7μs | ~3.5μs | ~3.2μs | ~18.4μs | 
| Speed Factor | 26.0x faster | 5.3x faster | 5.8x faster | Baseline | 
| Core Features | ||||
| Property Mapping | ✅ | ✅ | ✅ | ✅ | 
| Nested DTOs | ✅ | ✅ | ✅ | ✅ | 
| Collections | ✅ | ✅ | ✅ | ✅ | 
| Hidden Properties | ✅ | ✅ | ✅ | ✅ | 
| Immutability | ✅ | ✅ | ✅ | ✅ | 
| Validation | ||||
| Built-in Validation | ❌ | ❌ | ❌ | ✅ | 
| Custom Validation | ❌ | ❌ | ❌ | ✅ | 
| Validation Attributes | ❌ | ❌ | ❌ | ✅ | 
| Type Casting | ||||
| Automatic Casting | ❌ | ❌ | ✅ | ✅ | 
| DateTime Casting | ❌ | ❌ | ✅ | ✅ | 
| Enum Casting | ❌ | ❌ | ✅ | ✅ | 
| Custom Casts | ❌ | ❌ | ✅ | ✅ | 
| Advanced Features | ||||
| Computed Properties | ❌ | ❌ | ❌ | ✅ | 
| Lazy Properties | ❌ | ❌ | ❌ | ✅ | 
| Conditional Properties | ❌ | ❌ | ❌ | ✅ | 
| Hooks & Events | ❌ | ❌ | ❌ | ✅ | 
| Dot Notation Access | ✅ | ✅ | ✅ | ✅ | 
| Data Conversion | ||||
| Converter Support | ☑️ | ☑️ | ✅ | ✅ | 
| ConvertEmptyToNull | ✅ | ✅ | ✅ | ✅ | 
| JSON/XML Support | ☑️ | ☑️ | ✅ | ✅ | 
| Developer Experience | ||||
| IDE Autocomplete | ✅ | ✅ | ✅ | ✅ | 
| TypeScript Generation | ✅ | ✅ | ✅ | ✅ | 
| Constructor Promotion | ✅ | ✅ | ✅ | ✅ | 
| Property Attributes | ☑️ | ☑️ | ☑️ | ✅ | 
Legend:
- ✅ Fully supported
- ☑️ Partially supported or optional
- ❌ Not supported
Available Attributes
Section titled “Available Attributes”| Attribute | LiteDto #[UltraFast] | LiteDto | SimpleDto #[UltraFast] | SimpleDto | 
|---|---|---|---|---|
| Class Attributes | ||||
| #[UltraFast] | ✅ | ✅ | ✅ | ✅ | 
| #[ConverterMode] | ❌ | ✅ | ❌ | ✅ | 
| #[AutoCast] | ❌ | ❌ | ❌ | ✅ | 
| #[NoAttributes] | ❌ | ❌ | ❌ | ✅ | 
| #[NoCasts] | ❌ | ❌ | ❌ | ✅ | 
| #[NoValidation] | ❌ | ❌ | ❌ | ✅ | 
| #[ValidateRequest] | ❌ | ❌ | ❌ | ✅ | 
| Property Attributes | ||||
| #[MapFrom] | ✴️ | ✅ | ✴️ | ✅ | 
| #[MapTo] | ✴️ | ✅ | ✴️ | ✅ | 
| #[MapInputName] | ❌ | ❌ | ❌ | ✅ | 
| #[MapOutputName] | ❌ | ❌ | ❌ | ✅ | 
| #[Hidden] | ❌ | ✅ | ❌ | ✅ | 
| #[HiddenFromArray] | ❌ | ❌ | ❌ | ✅ | 
| #[HiddenFromJson] | ❌ | ❌ | ❌ | ✅ | 
| #[Visible] | ❌ | ❌ | ❌ | ✅ | 
| #[CastWith] | ✴️ | ✅ | ✴️ | ✅ | 
| #[EnumSerialize] | ❌ | ✅ | ❌ | ✅ | 
| #[ConvertEmptyToNull] | ❌ | ✅ | ❌ | ✅ | 
| #[DataCollectionOf] | ❌ | ✅ | ❌ | ✅ | 
| #[Computed] | ❌ | ❌ | ❌ | ✅ | 
| #[Lazy] | ❌ | ❌ | ❌ | ✅ | 
| #[Optional] | ❌ | ❌ | ❌ | ✅ | 
| Validation Attributes | ||||
| #[Required] | ❌ | ❌ | ❌ | ✅ | 
| #[RequiredIf] | ❌ | ❌ | ❌ | ✅ | 
| #[RequiredUnless] | ❌ | ❌ | ❌ | ✅ | 
| #[RequiredWith] | ❌ | ❌ | ❌ | ✅ | 
| #[RequiredWithout] | ❌ | ❌ | ❌ | ✅ | 
| #[Nullable] | ❌ | ❌ | ❌ | ✅ | 
| #[Sometimes] | ❌ | ❌ | ❌ | ✅ | 
| #[Email] | ❌ | ❌ | ❌ | ✅ | 
| #[Url] | ❌ | ❌ | ❌ | ✅ | 
| #[Uuid] | ❌ | ❌ | ❌ | ✅ | 
| #[Ip] | ❌ | ❌ | ❌ | ✅ | 
| #[Json] | ❌ | ❌ | ❌ | ✅ | 
| #[Min] | ❌ | ❌ | ❌ | ✅ | 
| #[Max] | ❌ | ❌ | ❌ | ✅ | 
| #[Between] | ❌ | ❌ | ❌ | ✅ | 
| #[Size] | ❌ | ❌ | ❌ | ✅ | 
| #[In] | ❌ | ❌ | ❌ | ✅ | 
| #[NotIn] | ❌ | ❌ | ❌ | ✅ | 
| #[Regex] | ❌ | ❌ | ❌ | ✅ | 
| #[StartsWith] | ❌ | ❌ | ❌ | ✅ | 
| #[EndsWith] | ❌ | ❌ | ❌ | ✅ | 
| #[Confirmed] | ❌ | ❌ | ❌ | ✅ | 
| #[ConfirmedBy] | ❌ | ❌ | ❌ | ✅ | 
| #[Same] | ❌ | ❌ | ❌ | ✅ | 
| #[Different] | ❌ | ❌ | ❌ | ✅ | 
| #[Unique] | ❌ | ❌ | ❌ | ✅ | 
| #[Exists] | ❌ | ❌ | ❌ | ✅ | 
| #[File] | ❌ | ❌ | ❌ | ✅ | 
| #[Image] | ❌ | ❌ | ❌ | ✅ | 
| #[Mimes] | ❌ | ❌ | ❌ | ✅ | 
| #[MimeTypes] | ❌ | ❌ | ❌ | ✅ | 
| Conditional Attributes | ||||
| #[WhenCallback] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenValue] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenEquals] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenIn] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenTrue] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenFalse] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenNull] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenNotNull] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenInstanceOf] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenContext] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenContextEquals] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenContextIn] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenContextNotNull] | ❌ | ❌ | ❌ | ✅ | 
| #[WhenAuth] (Laravel) | ❌ | ❌ | ❌ | ✅ | 
| #[WhenGuest] (Laravel) | ❌ | ❌ | ❌ | ✅ | 
| #[WhenCan] (Laravel) | ❌ | ❌ | ❌ | ✅ | 
| #[WhenRole] (Laravel) | ❌ | ❌ | ❌ | ✅ | 
| #[WhenGranted] (Symfony) | ❌ | ❌ | ❌ | ✅ | 
| #[WhenSymfonyRole] (Symfony) | ❌ | ❌ | ❌ | ✅ | 
| Other Attributes | ||||
| #[RuleGroup] | ❌ | ❌ | ❌ | ✅ | 
| #[WithMessage] | ❌ | ❌ | ❌ | ✅ | 
Legend:
- ✅ Fully supported
- ✴️ Can be re-enabled with UltraFast parameters (e.g., #[UltraFast(allowMapFrom: true)])
- ❌ Not supported
Detailed Comparison
Section titled “Detailed Comparison”Performance
Section titled “Performance”LiteDto is optimized for speed:
- ~4.4μs average operation time
- 5.3x faster than SimpleDto
- Minimal reflection overhead
- No validation or casting overhead
SimpleDto provides full features:
- ~18.4μs average operation time
- Includes validation and type casting
- Rich attribute system
- More overhead but more features
- Use #[UltraFast]attribute to skip validation/casting when not needed (~3.2μs, 5.8x faster)
Use Cases
Section titled “Use Cases”Choose LiteDto When:
Section titled “Choose LiteDto When:”✅ Performance is critical
- High-throughput APIs (1000+ requests/second)
- Real-time data processing
- Microservices communication
- Data transfer between layers
✅ Simple data structures
- No validation needed
- No type casting required
- Straightforward mapping
✅ Validation handled elsewhere
- Form validation in frontend
- API gateway validation
- Database constraints
Choose SimpleDto When:
Section titled “Choose SimpleDto When:”✅ Validation is required
- Form input validation
- API request validation
- Business rule enforcement
✅ Type casting needed
- DateTime conversion
- Enum mapping
- Custom type transformations
✅ Advanced features required
- Computed properties
- Lazy loading
- Conditional properties
- Hooks and events
✅ Complex data structures
- Nested validation
- Collection validation
- Cross-field validation
Migration Between DTOs
Section titled “Migration Between DTOs”From SimpleDto to LiteDto
Section titled “From SimpleDto to LiteDto”If you need better performance and don’t need validation:
// Before: SimpleDtoclass UserDto extends SimpleDto{    public string $name;    public string $email;    public int $age;}
// After: LiteDtoclass UserDto extends LiteDto{    public function __construct(        public readonly string $name,        public readonly string $email,        public readonly int $age,    ) {}}From LiteDto to SimpleDto
Section titled “From LiteDto to SimpleDto”If you need validation or type casting:
// Before: LiteDtoclass UserDto extends LiteDto{    public function __construct(        public readonly string $name,        public readonly string $email,        public readonly int $age,    ) {}}
// After: SimpleDtoclass UserDto extends SimpleDto{    public string $name;
    #[Email]    public string $email;
    #[Min(18)]    public int $age;}Performance Tips
Section titled “Performance Tips”LiteDto Optimization
Section titled “LiteDto Optimization”- Avoid #[ConverterMode]when only using arrays (~0.5μs overhead)
- Use readonlyproperties (required)
- Minimize nested DTOs
- Minimize attribute usage
SimpleDto Optimization
Section titled “SimpleDto Optimization”- Use #[UltraFast]mode when validation is not needed (~3.7μs)
- Enable caching for repeated use
- Minimize validation rules
- Use computed properties sparingly
Learn More
Section titled “Learn More”LiteDto Documentation
Section titled “LiteDto Documentation”- LiteDto Introduction - Getting started
- Creating LiteDtos - Best practices
- LiteDto Attributes - Available attributes
- LiteDto Performance - Optimization tips
SimpleDto Documentation
Section titled “SimpleDto Documentation”- SimpleDto Introduction - Getting started
- Creating Dtos - Best practices
- Validation - Validation rules
- Type Casting - Type conversion
- Performance Modes - UltraFast mode
