paulo / data-transfer-object
There is no license information available for the latest version (1.0.0) of this package.
Simple DTO wrapper
1.0.0
2024-02-15 05:24 UTC
Requires
- php: >=8.1
Requires (Dev)
- laravel/pint: ^1.13
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
README
Доступные аттрибуты
- PropertyIgnoreParse - игнорирует свойство объекта при парсинге массива
- PropertyIgnoreSerialize - игнорирует свойство при сериализации объекта
Example
class T extends DataTransferObject { #[PropertyMapTo('test.job.0')] #[PropertyMapFrom('tt')] #[PropertyParse(T::class, 'parse', true)] #[PropertySerialize(T::class, 'serString', true, 'string')] #[PropertySerialize(T::class, 'serInt', true, PhpType::Integer)] #[PropertySerialize(T::class, 'serNull', true, PhpType::NULL)] public mixed $t; public static function parse(mixed $v) { return 'Hello world!'; } public static function serString(string $v) { return substr($v, 0, 5); } public static function serInt(int $v) { return $v * 2; } public static function serNull(mixed $v) { return 'undefined'; } } $t = T::wrap(['tt' => null]); var_dump($t->toArray()); /* array(1) { ["test"]=> array(1) { ["job"]=> array(1) { [0]=> string(5) "Hello" } } } */