Download the PHP package rasclatt/smart-dto without Composer
On this page you can find all versions of the php package rasclatt/smart-dto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rasclatt/smart-dto
More information about rasclatt/smart-dto
Files in rasclatt/smart-dto
Package smart-dto
Short Description Fill Dtos with data using the mapping. Also allows rendering to different array key formats.
License MIT
Homepage https://github.com/rasclatt/nubersoft
Informations about the package smart-dto
SmartDto\Dto
Create and manipulate Data Transfer Objects
Basic Use
First, create your Dto:
Reference your Dto in your model
Basic Result:
Advanced Example
Revised Dto to include some model-esque features:
Advanced Result
This will produce a different result than the first example because it will run the "id()" method as well:
Parameter Conversion
You are able to convert the input array before assigning the keys to your Dto:
Convert Using A Constant
This will map to camel case.
This will then be mapped to your camel cased parameters:
If you have a string such as
'thedescription'
, it will not generate camel case because there is no way to know where to break. You would want to useafterConstruct()
method to generate that manually totheDescription
or use\SmartDto\Mapper
object to map two different arrays.
SmartDto\Mapper
This object will generate a string for copy and pasting to your DTO class by examining your input data:
This will produce a string that you can copy and paste:
Pass true
to the public function getAttributes(true);
to add types behind your parameters:
Map Two Arrays
You might find you need to take one return array and force it into a new array with different keys from the original (like an adapter). This allows you to take two arrays and map the keys and values from each array: