Download the PHP package taboritis/dto-wizard-php without Composer
On this page you can find all versions of the php package taboritis/dto-wizard-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download taboritis/dto-wizard-php
More information about taboritis/dto-wizard-php
Files in taboritis/dto-wizard-php
Package dto-wizard-php
Short Description Data Transfer Objects with nested structures in PHP
License MIT
Informations about the package dto-wizard-php
DTO Wizard
- DTO Wizard
- What problem does it solve?
- Basic usage
- Readonly properties
- Private properties
- Default values
- Casting values by examples
- Boolean
- Strings
- Numbers
- Arrays
- DateTime
- Objects
- Collections
What problem does it solve?
Sometimes it may be necessary to convert a complex multi-layered array into an object-oriented format that preserves the original structure.
To achieve this result DTO-Wizard provides a straightforward API that eliminates the need for repetitive iterations and transformations.
Basic usage
Readonly properties
It is strongly recommended to use readonly properties as often as possible. This will have the same effect as unchanged data.
Private properties
Although setting private properties is not recommended in DTO, it can be done using DtoWizard/Factory. However, it is important to remember that in such cases, you must also create a getter that allows access to the given property. Of course, in this situation, you can benefit from the advantages of using a getter, such as its ability to handle properties that are unset or nullable.
Default values
Default properties can be set in 3 ways:
- in the property itself (warning: readonly properties cannot have default value)
- in the constructor
- in the getter.
It's entirely up to you to decide whether and how to utilize this feature.
Casting values by examples
In simple cases, PHP's type juggling mechanism casts assigned property values to the necessary type. https://www.php.net/manual/en/language.types.type-juggling.php
Boolean
Strings
Numbers
Arrays
// TODO
DateTime
Objects
Collections
// TODO: must implement Traversable