trait-dto, Packagist
To install package, you need run command:
composer require akbsit/trait-dto
Create DTO class with trait DtoTrait
:
<?php namespace App\Classes;
use Akbsit\TraitDto\DtoTrait;
/**
* Class ExampleDto
* @package App\Classes
*/
class ExampleDto
{
use DtoTrait;
/* @var int */
public $iIntProperty;
/* @var string */
public $sStringProperty;
/* @var array */
public $arArrayProperty;
}
Create object:
$oExampleDto = ExampleDto::instance()->create([
'iIntProperty' => 10,
'sStringProperty' => 'string',
'arArrayProperty' => [
'key1' => 'value1',
'key2' => 'value2',
],
]);
object(App\Classes\ExampleDto)#208 (3) {
["iIntProperty"]=>
int(10)
["sStringProperty"]=>
string(6) "string"
["arArrayProperty"]=>
array(2) {
["key1"]=>
string(6) "value1"
["key2"]=>
string(6) "value2"
}
}