Download the PHP package sj/dtomatic without Composer
On this page you can find all versions of the php package sj/dtomatic. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package dtomatic
Short Description Dtomatic is a flexible, reflection-based object mapper for Laravel applications. It automatically maps data from source objects to DTO classes, including support for nested objects and collections
License MIT
Informations about the package dtomatic
📦 Dtomatic
Dtomatic is a flexible, reflection-based object-to-DTO mapper for Laravel applications. It automatically maps data from source models or plain objects to strongly typed DTO classes — including support for:
- Nested DTO mapping
- Collections
- Custom value converters
- Ignoring specific properties
- Strict type validation
- Mapping values via custom model getters
- Clean integration with Laravel services
📥 Installation
Install the package via Composer:
🔧 Configuration
To publish the configuration file:
This will publish a config file at:
Example content:
🏷️ Available Attributes
Dtomatic supports the following PHP attributes to customize DTO mapping behavior:
1. #[ArrayOf(Type::class)]
- Use this attribute to specify the type of objects inside an array or collection property.
- Enables automatic mapping of nested collections of DTOs.
2. #[Ignore]
- Marks a DTO property to be ignored during mapping.
- Useful for excluding properties you do not want to populate.
3. #[Converter(ConverterClass::class)]
- Specifies a custom converter class for a particular property.
- The converter class must implement a
convert($value)method returning the converted value.
🚀 Basic Usage
Example DTO class:
Example mapping in your controller or service:
📑 Nested Mapping Example
Nested Collections Mapping with #[ArrayOf] Attribute
Example usage:
📚 Collection Mapping
🎛️ Property-Level Converter Example
DTO usage:
🌍 Global Converter Example
In config/dtomatic.php:
Converter class:
🛑 Ignoring Properties
✅ Strict Type Validation
When strict_types is enabled in config, Dtomatic throws InvalidArgumentException on type mismatches.
🎣 Mapping From Getter Methods
Model:
DTO:
📖 Why Use Dtomatic over other solutions?
- Laravel Resources require manual array structures.
- Dtomatic uses native typed DTO classes with reflection and PHP Attributes.
- Supports nested mapping, collections, global/property converters, validation, and getter resolution.
- Clean, typed, scalable API layer.
📃 License
MIT © Shihab Jamil