Skip to content

Commit 5782b3a

Browse files
authored
feat: add IterableMapperInterface getter to the non-framework factory (#54)
* feat: add `IterableMapperInterface` getter to the non-framework factory * add docs
1 parent c30d661 commit 5782b3a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.2.0
44

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

78
## 1.1.2
89

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,23 @@ composer require rekalogika/mapper
1919
```php
2020
use App\Entity\Book;
2121
use Rekalogika\Mapper\MapperInterface;
22+
use Rekalogika\Mapper\IterableMapperInterface;
2223

2324
/** @var MapperInterface $mapper */
25+
/** @var IterableMapperInterface $mapper */
2426
/** @var Book $book */
27+
/** @var iterable<Book> $books */
2528

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

2831
// or map to an existing object
2932

3033
$bookDto = new BookDto();
3134
$mapper->map($book, $bookDto);
35+
36+
// map iterable of books
37+
38+
$bookDtos = $mapper->mapIterable($books, BookDto::class);
3239
```
3340

3441
## Why Use a Mapper?

src/MapperFactory.php

+10
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class MapperFactory
139139
private ?ArrayLikeMetadataFactoryInterface $arrayLikeMetadataFactory = null;
140140
private ?MainTransformerInterface $mainTransformer = null;
141141
private ?MapperInterface $mapper = null;
142+
private ?IterableMapperInterface $iterableMapper = null;
142143
private ?MappingFactoryInterface $mappingFactory = null;
143144
private ?ObjectCacheFactoryInterface $objectCacheFactory = null;
144145
private ?SubMapperFactoryInterface $subMapperFactory = null;
@@ -227,6 +228,15 @@ public function getMapper(): MapperInterface
227228
return $this->mapper;
228229
}
229230

231+
public function getIterableMapper(): IterableMapperInterface
232+
{
233+
if (null === $this->iterableMapper) {
234+
$this->iterableMapper = new Mapper($this->getMainTransformer());
235+
}
236+
237+
return $this->iterableMapper;
238+
}
239+
230240
//
231241
// property info
232242
//

0 commit comments

Comments
 (0)