Download the PHP package mohammedmanssour/super-simple-dto without Composer
On this page you can find all versions of the php package mohammedmanssour/super-simple-dto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mohammedmanssour/super-simple-dto
More information about mohammedmanssour/super-simple-dto
Files in mohammedmanssour/super-simple-dto
Package super-simple-dto
Short Description Creating data transfer objects with the power of php objects
License MIT
Homepage https://github.com/mohammedmanssour/super-simple-dto
Informations about the package super-simple-dto
Super Simple DTO
Creating data transfer objects with the power of php objects. No php attributes, no reflection api, and no other under the hook work.
This is a laravel package and laravel/framework
is part of the package dependencies. Please, make sure you have no problem with that before using.
Why Bother.
The spatie team has already created an awesome package that serves as a great solution for DTO objects. But, for me, it's full of features that I don't use and it seems like an overkill for me when I just wanted simple solution for DTO work.
Installation
You can install the package via composer:
Usage
-
Apply the
AsDTO
trait to your data object - use on of these static methods to convert data into DTP:
fromCollection
: converts collections to DTO objects.fromArray
: converts array to DTO objects.fromModel
: converts model to DTO objects. It works with the data available with$model->getAttributes()
method.fromRequest
: converts laravel requests to DTO objects. It works with the data available withvalidated()
. In casevalidated
method is not available, it'll use theall()
method. You can also force using request'sall
method by passing true as a second parameter.
How DTO is populated:
The AsDTO
will assign values to DTO attributes depending of the keys. and attributes that has no key match will not be initialized/assigned
Handling special attributes:
In case you have an attribute that needs special care. you can add a method to your dto than have the same name as your attribute and take care of the conversion.
converting DTO to array
You can convert dto to array using DTO method
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Mohammed Manssour
- All Contributors
License
The MIT License (MIT). Please see License File for more information.