Download the PHP package negreanucalin/sparkle-dto without Composer
On this page you can find all versions of the php package negreanucalin/sparkle-dto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package sparkle-dto
Sparkle DTO
Small, dependency-light Data Transfer Objects for PHP, inspired by Laravel's Eloquent attribute conventions. Feed it an array (a request body, a DB row, an API response) and get back a typed, predictable object.
Install
Requires PHP 7.1.8+ or 8.x. The only runtime dependency is nesbot/carbon for date casting.
Quick start
Features
- Casting to
int,float,bool,string,array,date/datetime(Carbon), or another DTO class. - Custom casts via a static callable:
'flag' => [MyDto::class, 'castYesNo']. The method receives the value and the full input array. - Nested DTOs and lists. A cast to a DTO class hydrates a single object or a list, depending on the input shape. Add
*to the key ('users*') to keep string keys and get a map instead. - Computed attributes. Any
getXxxAttribute()method becomes a snake_case property (getFullNameAttribute→full_name). Recomputed when you set a property. - Aliases rename incoming keys before anything else runs.
$hiddenkeeps a value accessible on the object but out of serialization.$fillablewhitelists which keys are accepted. Use one or the other, not both.$datesmarks extra fields to convert to Carbon without listing them in$casts.- Implements
ArrayAccessandJsonSerializable;(string) $dtogives JSON. MyDto::hydrate($rows)builds a list of DTOs from a list of arrays.DataTransferObjectWithIdadds a random hexidcomputed attribute.
Tests
License
MIT
All versions of sparkle-dto with dependencies
PHP Build Version
Package Version
The package negreanucalin/sparkle-dto contains the following files
Loading the files please wait ...