Skip to content

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

LiteDto is designed for maximum performance when you need fast data transfer without validation or type casting.

use event4u\DataHelpers\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 provides full validation and type casting with a rich feature set.

use event4u\DataHelpers\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 Tip: Use #[UltraFast] attribute for 3-4x faster performance when validation is not needed:

use event4u\DataHelpers\SimpleDto;
use event4u\DataHelpers\SimpleDto\Attributes\UltraFast;
use event4u\DataHelpers\SimpleDto\Attributes\MapFrom;
use event4u\DataHelpers\SimpleDto\Attributes\Hidden;
#[UltraFast] // Auto-detect attributes, skip validation (~2-3μs)
class UserDto extends SimpleDto
{
public function __construct(
public readonly string $name,
#[MapFrom('email_address')] // Still works!
public readonly string $email,
#[Hidden] // Still works!
public readonly string $password,
) {}
}
// Ultra-fast creation: ~2-3μs (3-4x faster than normal SimpleDto!)
$user = UserDto::from([
'name' => 'John',
'email_address' => 'john@example.com',
'password' => 'secret',
]);
FeatureLiteDto #[UltraFast]LiteDtoSimpleDto #[UltraFast]SimpleDto
Creation Performance~2.3μs~3.7μs~4.7μs~5.7μs
Creation Speed Factor2.4x faster1.5x faster1.2x fasterBaseline
Serialization Performance~4.4μs~6.5μs~30.1μs~31.8μs
Serialization Speed Factor7.3x faster4.9x faster1.1x fasterBaseline
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
AttributeLiteDto #[UltraFast]LiteDtoSimpleDto #[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
  • ☑️ Partially supported or optional -✴️ Can be re-enabled with UltraFast parameters (e.g., #[UltraFast(allowMapFrom: true)])
  • ❌ Not supported

Performance Notes:

  • #[UltraFast]: Available for both LiteDto and SimpleDto
    • LiteDto: Can re-enable specific attributes (e.g., #[UltraFast(allowMapFrom: true)])
    • SimpleDto: Auto-detects which attributes are used and processes only those
  • #[ConverterMode]: Available for LiteDto (normal mode) and SimpleDto
  • #[AutoCast]: Enables automatic type casting for native PHP types (SimpleDto only)
  • #[NoAttributes]: Skips ALL attribute processing for maximum performance (SimpleDto only)
  • #[NoCasts]: Disables all type casting (SimpleDto only)
  • #[NoValidation]: Skips ALL validation for trusted data sources (SimpleDto only)
  • #[ValidateRequest]: Enables automatic request validation in Laravel/Symfony (SimpleDto only)
  • #[Optional]: Zero overhead when not used (opt-in via feature flag, SimpleDto only)

LiteDto is optimized for speed:

  • ~4.5μs average creation time (normal mode)
  • ~2.0μs with #[UltraFast] (3.8x faster than SimpleDto)
  • Minimal reflection overhead
  • No validation or casting overhead
  • Use #[UltraFast] attribute for even better performance

SimpleDto provides full features:

  • ~7.6μs average creation time (normal mode)
  • ~7.7μs with #[UltraFast] (1.0x faster)
  • Includes validation and type casting
  • Rich attribute system
  • More overhead but more features
  • Use #[UltraFast] attribute to skip validation/casting when not needed

✅ 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

✅ Validation is required

  • Form input validation
  • API request validation
  • Business rule enforcement
  • Tip: Use on-demand validation for best performance (create fast, validate when needed)

✅ Type casting needed

  • DateTime conversion
  • Enum mapping
  • Custom type transformations

✅ Advanced features required

  • Conditional properties
  • Hooks and events
  • Dot notation access

✅ Complex data structures

  • Nested validation
  • Collection validation
  • Cross-field validation
  • Avoid #[ConverterMode] when only using arrays (~0.5μs overhead)
  • Use readonly properties (required)
  • Minimize nested DTOs
  • Minimize attribute usage
  • Use #[UltraFast] for even better performance (~2.0μs)
  • Use #[UltraFast] mode when validation is not needed (~7.7μs)
  • Enable caching for repeated use
  • Minimize validation rules
  • Use computed properties sparingly

If you need better performance and don’t need validation:

// Before: SimpleDto
class UserDto extends SimpleDto
{
public function __construct(
public readonly string $name,
public readonly string $email,
public readonly int $age,
) {}
}
// After: LiteDto
class UserDto extends LiteDto
{
public function __construct(
public readonly string $name,
public readonly string $email,
public readonly int $age,
) {}
}

If you need validation or type casting:

// Before: LiteDto
class UserDto extends LiteDto
{
public function __construct(
public readonly string $name,
public readonly string $email,
public readonly int $age,
) {}
}
// After: SimpleDto
class UserDto extends SimpleDto
{
public function __construct(
public readonly string $name,
#[Email]
public readonly string $email,
#[Min(18)]
public readonly int $age,
) {}
}
  • Avoid #[ConverterMode] when only using arrays (~0.5μs overhead)
  • Use readonly properties (required)
  • Minimize nested DTOs
  • Minimize attribute usage
  • Use #[UltraFast] mode when validation is not needed (~2-3μs, 3-4x faster)
  • UltraFast auto-detects which attributes are used (zero overhead for unused features)
  • Enable caching for repeated use
  • Minimize validation rules
  • Use computed properties sparingly
  • Combine #[UltraFast] with #[ConverterMode] for JSON/XML support