25-63x Faster
Code generation at build time means zero runtime reflection. The only code-gen approach in PHP for DTOs.
Framework-agnostic DTOs with zero runtime overhead, perfect IDE support, and TypeScript generation.
Define your DTOs with the fluent PHP builder:
// config/dto.php
use PhpCollective\Dto\Config\{Dto, Field, Schema};
return Schema::create()
->dto(Dto::create('User')->fields(
Field::int('id')->required(),
Field::string('name')->required(),
Field::string('email')->required(),
Field::dto('address', 'Address'),
))
->dto(Dto::create('Address')->fields(
Field::string('street'),
Field::string('city'),
Field::string('country'),
))
->toArray();Generate and use:
vendor/bin/dto generate$user = UserDto::createFromArray($apiResponse);
$user->getName(); // string
$user->getAddress(); // AddressDto|null
$user->getAddressOrFail(); // AddressDto (throws if null)composer require php-collective/dto| Framework | Package |
|---|---|
| CakePHP | dereuromark/cakephp-dto |
| Laravel | php-collective/laravel-dto |
| Symfony | php-collective/symfony-dto |