Skip to content

Commit

Permalink
Changed CollectionMapper to map any expression type instead of just M…
Browse files Browse the repository at this point in the history
…appings.
  • Loading branch information
Paul committed Jun 12, 2017
1 parent 9722621 commit b0a28a0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/CollectionMapper.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
<?php
namespace ScriptFUSION\Mapper;

use ScriptFUSION\Mapper\Strategy\Strategy;

/**
* Maps collections of records.
*/
class CollectionMapper extends Mapper
{
/**
* @param \Iterator $collection
* @param Mapping|null $mapping
* @param Strategy|Mapping|array|mixed $expression Expression.
* @param mixed $context
*
* @return \Generator
*
* @throws InvalidRecordException A record in the specified collection was not an array type.
*/
public function mapCollection(\Iterator $collection, Mapping $mapping = null, $context = null)
public function mapCollection(\Iterator $collection, $expression = null, $context = null)
{
foreach ($collection as $key => $record) {
if (!is_array($record)) {
throw new InvalidRecordException('Record must be an array.');
}

yield $key => $mapping
? $this->mapMapping($record, $mapping, $context, $key)
yield $key => $expression !== null
? $this->mapMapping($record, $expression, $context, $key)
: $record;
}
}
Expand Down

0 comments on commit b0a28a0

Please sign in to comment.