rinsvent / data2dto
Convert data to dto object
v0.0.18
2022-04-02 07:35 UTC
Requires
- php: ^8.0
- ext-ctype: *
- ext-iconv: *
- ext-json: *
- rinsvent/attribute-extractor: ^0.0
- rinsvent/transformer: ^0.
- symfony/string: ^5.3
Requires (Dev)
- codeception/codeception: ^4.1
- codeception/module-asserts: ^1.0.0
- codeception/module-phpbrowser: ^1.0.0
README
Data2dto
Установка
composer require rinsvent/data2dto
Пример
Описания ДТО
class BuyRequest { public string $phrase; public int $length; public bool $isFirst; } interface BarInterface { } class Bar implements BarInterface { public float $barField; } class HelloRequest { #[Trim] public string $surname; #[PropertyPath('fake_age')] public int $age; public array $emails; #[DTOMeta(class: Author::class)] public array $authors; public BuyRequest $buy; #[DTOMeta(class: Bar::class)] public BarInterface $bar; }
Использование
use Rinsvent\Data2DTO\Data2DtoConverter; $data2DtoConverter = new Data2DtoConverter(); $dto = $data2DtoConverter->convert([ 'surname' => ' asdf', 'fake_age' => 3, 'emails' => [ 'sfdgsa', 'af234f', 'asdf33333' ], 'authors' => [ [ 'name' => 'Tolkien', ], [ 'name' => 'Sapkovsky' ] ], 'buy' => [ 'phrase' => 'Buy buy!!!', 'length' => 10, 'isFirst' => true, 'extraData2' => '1234' ], 'bar' => [ 'barField' => 32 ], 'extraData1' => 'qwer' ], new HelloRequest);