From ef4dd7d183243919096809e6dd6232b5bb9826e9 Mon Sep 17 00:00:00 2001 From: Rinsvent Date: Fri, 1 Apr 2022 22:42:33 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.md | 122 +++--------------------------------------------------- 1 file changed, 5 insertions(+), 117 deletions(-) diff --git a/Readme.md b/Readme.md index c5b28f9..0956dd5 100644 --- a/Readme.md +++ b/Readme.md @@ -10,124 +10,12 @@ composer require rinsvent/transformer ``` ## Пример - -### Описания ДТО -```php -class BuyRequest -{ - public string $phrase; - public int $length; - public bool $isFirst; -} - -interface BarInterface -{ - -} - -class Bar implements BarInterface -{ - public float $barField; -} - -#[HelloSchema] -class HelloRequest -{ - #[Trim] - public string $surname; - #[DataPath('fake_age')] - public int $age; - public array $emails; - public array $authors; - public array $authors2; - public array $authors3; - public BuyRequest $buy; - public BarInterface $bar; -} -``` ### Использование ```php -use Rinsvent\Transformer\Transformer; - -$helloRequest = new HelloRequest; -$helloRequest->surname = ' asdf'; -$helloRequest->age = 3; -$helloRequest->emails =[ - 'sfdgsa', - 'af234f', - 'asdf33333' -]; -$author1 = new Author(); -$author1->name = 'Tolkien'; -$author2 = new Author(); -$author2->name = 'Sapkovsky'; -$helloRequest->authors = [ - $author1, - $author2 -]; -$helloRequest->authors2 = [ - [ - "name" => "Tolkien" - ], - [ - "name" => "Sapkovsky" - ] -]; -$helloRequest->authors3 = [ - [ - "name" => "Tolkien" - ], - [ - "name" => "Sapkovsky" - ] -]; -$buy = new BuyRequest(); -$buy->phrase = 'Buy buy!!!'; -$buy->length = 10; -$buy->isFirst = true; -$helloRequest->buy = $buy; -$bar = new Bar(); -$bar->barField = 32; -$helloRequest->bar = $bar; - -$transformer = new Transformer(); -$dto = $transformer->convert($helloRequest); -``` -### Результат -```php -$dto = [ - "surname" => "asdf", - "fake_age" => 3, - "emails" => [ - "sfdgsa", - "af234f", - "asdf33333" - ], - "authors" => [ - [ - "name" => "Tolkien" - ], - [ - "name" => "Sapkovsky" - ] - ], - "authors2" => [ - [ - "name" => "Tolkien" - ], - [ - "name" => "Sapkovsky" - ] - ], - "authors3" => [], - "buy" => [ - "phrase" => "Buy buy!!!", - "length" => 10, - "isFirst" => true - ], - "bar" => [ - "barField" => 32 - ] -] +$t = new Transformer(); +$dt = new \DateTime('2022-04-01'); +$dt->setTime(5, 23, 21); +$actual = $t->transform($dt, new Transformer\DateTimeFormat()); +$this->assertEquals('2022-04-01T05:23:21+00:00', $actual); ```