Skip to content

Commit

Permalink
doc: fixes (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Apr 29, 2024
1 parent 5782b3a commit 789f72e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ composer require rekalogika/mapper
```php
use App\Entity\Book;
use Rekalogika\Mapper\MapperInterface;
use Rekalogika\Mapper\IterableMapperInterface;

// map a single object:

/** @var MapperInterface $mapper */
/** @var IterableMapperInterface $mapper */
/** @var Book $book */
/** @var iterable<Book> $books */

$bookDto = $mapper->map($book, BookDto::class);
$result = $mapper->map($book, BookDto::class);

// or map to an existing object
// map a single object to an existing object:

$bookDto = new BookDto();
$mapper->map($book, $bookDto);

// map iterable of books
// map an iterable of objects:

/** @var IterableMapperInterface $iterableMapper */
/** @var iterable<Book> $books */

$bookDtos = $mapper->mapIterable($books, BookDto::class);
$bookDtos = $iterableMapper->mapIterable($books, BookDto::class);
```

## Why Use a Mapper?
Expand Down

0 comments on commit 789f72e

Please sign in to comment.