You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
491 B
30 lines
491 B
<?php
|
|
|
|
namespace DbCopy\Transform;
|
|
|
|
class ValueMap extends Transform
|
|
{
|
|
private $_map;
|
|
|
|
public function __construct(array $map)
|
|
{
|
|
$this->_map = $map;
|
|
}
|
|
|
|
public static function create(array $map): ValueMap
|
|
{
|
|
return new ValueMap($map);
|
|
}
|
|
|
|
public function __invoke($record): ?array
|
|
{
|
|
foreach ($this->_map as $field=>$values)
|
|
{
|
|
if (isset($record[$field]) && isset($values[$record[$field]]))
|
|
{
|
|
$record[$field] = $values[$record[$field]];
|
|
}
|
|
}
|
|
return $record;
|
|
}
|
|
}
|
|
|