Download the PHP package maduser/argon-dto without Composer
On this page you can find all versions of the php package maduser/argon-dto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maduser/argon-dto
More information about maduser/argon-dto
Files in maduser/argon-dto
Package argon-dto
Short Description A PHP package for Data Transfer Objects (DTOs)
License MIT
Informations about the package argon-dto
Argon DTO
A lightweight PHP DTO implementation with support for array and JSON hydration, serialization, and optional auto-mapping using field constants. Reflection at runtime is avoided by design.
Requirements
- PHP 8.2+
- Composer
Installation
Overview
This package provides:
- A base
AbstractDTOclass for immutable data transfer objects. - Optional auto-mapping via
AutoMappableInterfaceandAutoMap. - Consistent serialization via
toArray()andtoJson(). - Custom exceptions for misconfiguration or serialization errors.
Usage
Simple DTO
For a basic DTO, just extend AbstractDTO:
Auto-Mapping DTO
If you want array-to-constructor mapping without manually unpacking arrays:
You can then hydrate from arrays or JSON:
Accessing Data
Mapping Logic
If your DTO implements AutoMappableInterface, you must define a mapFromArray() method. You can implement this manually or use the provided AutoMap trait. The trait uses MAPPABLE_FIELDS to determine which keys to extract from the input array and in what order:
- The order of keys in the input array is irrelevant.
- Extra keys in the input array are ignored.
Error Handling
DTOConfigurationException– DTO lacks required mapping behavior.DTOMappingException– Missing fields or invalidMAPPABLE_FIELDS.DTOSerializationException– JSON encoding/decoding failures.
Testing
License
MIT