ali-eltaweel / dto
There is no license information available for the latest version (1.1.0) of this package.
Data Transfer Object.
1.1.0
2025-06-28 00:11 UTC
Requires
- php: ^8.1
- ext-mbstring: *
- ali-eltaweel/array-subscript: ^1.0.0
- ali-eltaweel/computed-properties: ^1.0.1
This package is auto-updated.
Last update: 2025-06-28 00:11:39 UTC
README
Data Transfer Object
Installation
Install dto via Composer:
composer require ali-eltaweel/dto
Usage
Object
Data transfer objects have well defined fields and types.
use DTO\DataTransferObject; class InputDirectory extends DataTransferObject { public final function __construct(string $path, float $maxDepth = 32, bool $followSymlinks = true) { parent::__construct(func_get_args()); } }
$inputDirectory = InputDirectory::fromArray([ 'path' => '/var/www/html' ]);
Map
Data transfer maps - on the other hands - don't have well defined fields and accept all fields.
use DTO\DataTransferMap; class LookupTable extends DataTransferMap { }
Maps can enforce a type for all fields via the __v
method:
use DTO\DataTransferMap; class LookupTable extends DataTransferMap { function __v(string $field) {} }
Collection
Data transfer collections are used to hold multiple data transfer objects.
use DTO\DataTransferCollection; class InputDirectories extends DataTransferCollection { function __v(InputDirectory $field) {} }