zawiszaty / auto-dto
此包的最新版本(v3.0.0)没有可用的许可信息。
从类自动生成 DTO
v3.0.0
2019-08-05 11:31 UTC
Requires (Dev)
- phpunit/phpunit: ^8.3
This package is auto-updated.
Last update: 2024-09-05 23:43:03 UTC
README
从类生成 DTO
示例
class FakeObjectDTO extends ObjectDTO { public function __construct(object $class) { parent::__construct($class,FakeClass::class); } } /// OR class FakeArrayDTO extends ArrayDTO { public function __construct(array $params) { parent::__construct($params, FakeClass::class); } }
如何使用
$dateTime = new \DateTime(); $fakeClass = new FakeClass(1, 'test', $dateTime); $fakeDTO = new FakeObjectDTO($fakeClass); $this->assertSame(1, $fakeDTO->id); $this->assertSame('test', $fakeDTO->name); $this->assertSame($dateTime, $fakeDTO->createdAt); /// OR $dateTime = new \DateTime(); $fakeDTO = new FakeArrayDTO([ 'id' => 1, 'name' => 'test', 'createdAt' => $dateTime ]); $this->assertSame(1, $fakeDTO->id); $this->assertSame('test', $fakeDTO->name); $this->assertSame($dateTime, $fakeDTO->createdAt);
并且类与基类具有相同的属性和相同的属性值