Download the PHP package litea/dto without Composer
On this page you can find all versions of the php package litea/dto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package dto
Short Description Data transfer library that helps you to deal with unknown data
License MIT
Informations about the package dto
đ PHP Data Transfer Library
No need to read the details regarding the motivation behind the DTO?
đ Jump right to action!
We tried to solve this conundrum:
And now, with the Data Transfer Library:
đ Documentation
Bellow you will find the basic usage of this library. For more details see the documentation located in the docs directory of this repository.
Table of contents
- âšī¸ About
- đ Installation
- đ Basic usage
About
When dealing with an external data, it usually comes in very generic and dynamic form which is hard to reason about when returning to your code after a while.
This can be solved by so-called Data Transfer Objects (DTOs), which provide object wrapper with static and hopefully typed properties through which you can access the underlying values.
These objects get repetitive very quickly and after second or third DTO you reach for good old CTRL+C, CTRL+V which can be very error prone and hard to maintain.
This is a real-life example of DTO object that helps you to give you better control over the incoming data:
As you can see when you need to maintain dozens of those it becomes very self-evident that there is a place for improvement. That's why we decided to extract some of the common DTO features and provide them in the form of this package.
Installation
The easiest way to install this library is using composer:
Basic usage
Without DTO
Now imagine you use this service multiple times across your application. You need to pay extra attention to not to make mistakes or typos regarding the field namings. Your IDE can't help you here.
With DTO
First of all we need an object, that will represent the data:
Then we fetch the data as usual:
That's it. As you can see, in the simplest form using the DTO object is the
matter of defining one class that extends Litea\DataTransfer\DataObject
and then calling MyObject::create
.
To learn more about available configuration options see the examples.