akbsit / trait-dto
Trait help to create dto objects.
1.0.3
2023-09-16 18:03 UTC
Requires
- php: ^8.1
- akbsit/trait-singleton: ^1.0
- dusank/knapsack: ^10.0
This package is auto-updated.
Last update: 2024-12-16 21:27:40 UTC
README
Install
To install package, you need run command:
composer require akbsit/trait-dto
Example
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"
}
}