for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace mindplay\sql\model\components;
use mindplay\sql\framework\Mapper;
use mindplay\sql\framework\mappers\BatchMapper;
use mindplay\sql\framework\mappers\RecordMapper;
/**
* This trait implements support for mapping of results.
*/
trait Mappers
{
* @var Mapper[] list of Mappers
protected array $mappers = [];
* Append a Mapper instance to apply when each batch of a record-set is fetched.
*
* @param Mapper $mapper
* @see mapRecords() to map an anonymous function against every record
* @see mapBatches() to map an anonymous function against each batch of records
* @return $this
public function map(Mapper $mapper): static
$this->mappers[] = $mapper;
return $this;
}
* Map an anonymous function against every record.
* @param callable $mapper function (mixed $record) : mixed
public function mapRecords(callable $mapper): static
$this->mappers[] = new RecordMapper($mapper);
* Map an anonymous function against each batch of records.
* @param callable $mapper function (array $record_set) : array
public function mapBatches(callable $mapper): static
$this->mappers[] = new BatchMapper($mapper);