Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add IterableMapperInterface getter to the non-framework factory #54

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.2.0

* feat: add `IterableMapperInterface` for mapping iterables
* feat: add `IterableMapperInterface` getter to the non-framework factory

## 1.1.2

Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ composer require rekalogika/mapper
```php
use App\Entity\Book;
use Rekalogika\Mapper\MapperInterface;
use Rekalogika\Mapper\IterableMapperInterface;

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

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

// or map to an existing object

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

// map iterable of books

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

## Why Use a Mapper?
Expand Down
10 changes: 10 additions & 0 deletions src/MapperFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class MapperFactory
private ?ArrayLikeMetadataFactoryInterface $arrayLikeMetadataFactory = null;
private ?MainTransformerInterface $mainTransformer = null;
private ?MapperInterface $mapper = null;
private ?IterableMapperInterface $iterableMapper = null;
private ?MappingFactoryInterface $mappingFactory = null;
private ?ObjectCacheFactoryInterface $objectCacheFactory = null;
private ?SubMapperFactoryInterface $subMapperFactory = null;
Expand Down Expand Up @@ -227,6 +228,15 @@ public function getMapper(): MapperInterface
return $this->mapper;
}

public function getIterableMapper(): IterableMapperInterface
{
if (null === $this->iterableMapper) {
$this->iterableMapper = new Mapper($this->getMainTransformer());
}

return $this->iterableMapper;
}

//
// property info
//
Expand Down
Loading