Commit 5782b3a 1 parent c30d661 commit 5782b3a Copy full SHA for 5782b3a
File tree 3 files changed +19
-1
lines changed
3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 3
3
## 1.2.0
4
4
5
5
* feat: add ` IterableMapperInterface ` for mapping iterables
6
+ * feat: add ` IterableMapperInterface ` getter to the non-framework factory
6
7
7
8
## 1.1.2
8
9
Original file line number Diff line number Diff line change @@ -19,16 +19,23 @@ composer require rekalogika/mapper
19
19
``` php
20
20
use App\Entity\Book;
21
21
use Rekalogika\Mapper\MapperInterface;
22
+ use Rekalogika\Mapper\IterableMapperInterface;
22
23
23
24
/** @var MapperInterface $mapper */
25
+ /** @var IterableMapperInterface $mapper */
24
26
/** @var Book $book */
27
+ /** @var iterable<Book > $books */
25
28
26
- $result = $mapper->map($book, BookDto::class);
29
+ $bookDto = $mapper->map($book, BookDto::class);
27
30
28
31
// or map to an existing object
29
32
30
33
$bookDto = new BookDto();
31
34
$mapper->map($book, $bookDto);
35
+
36
+ // map iterable of books
37
+
38
+ $bookDtos = $mapper->mapIterable($books, BookDto::class);
32
39
```
33
40
34
41
## Why Use a Mapper?
Original file line number Diff line number Diff line change @@ -139,6 +139,7 @@ class MapperFactory
139
139
private ?ArrayLikeMetadataFactoryInterface $ arrayLikeMetadataFactory = null ;
140
140
private ?MainTransformerInterface $ mainTransformer = null ;
141
141
private ?MapperInterface $ mapper = null ;
142
+ private ?IterableMapperInterface $ iterableMapper = null ;
142
143
private ?MappingFactoryInterface $ mappingFactory = null ;
143
144
private ?ObjectCacheFactoryInterface $ objectCacheFactory = null ;
144
145
private ?SubMapperFactoryInterface $ subMapperFactory = null ;
@@ -227,6 +228,15 @@ public function getMapper(): MapperInterface
227
228
return $ this ->mapper ;
228
229
}
229
230
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
+
230
240
//
231
241
// property info
232
242
//
You can’t perform that action at this time.
0 commit comments