apfelfrisch / data-transfer-object
Installs: 16 565
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^5.2
- vimeo/psalm: ^4.7
README
This package is heavily inspired by spatie/data-transfer-object. The main difference is that the DataTransferObject doesn't come with a constructor. That makes the Initialization less magical which is nicer for static analysis.
Installation
You can install the package via composer:
composer require apfelfrisch/data-transfer-object
Usage
Here's what a DTO looks like:
use Apfelfrisch\DataTransferObject; use Apfelfrisch\DataTransferObject\Casters\DateTimeCast; class MyDTO extends DataTransferObject { public function __construct( public int $a, public float $b, public OtherDTO $otherDTO, #[DateTimeCast] public DateTime $date, ) { } }
You could construct this DTO with Parameter casting like so:
$dto = MyDTO::fromArrayWithCast([ 'a' => 1, 'b' => 2.2, 'otherDTO' => ['id' => 3], 'date' => '2021-05-01' );