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.
31 lines
485 B
31 lines
485 B
<?php
|
|
|
|
namespace DbCopy\Transform;
|
|
|
|
class FieldMap extends Transform
|
|
{
|
|
private $_fields;
|
|
|
|
public function __construct(array $fields)
|
|
{
|
|
$this->_fields = $fields;
|
|
}
|
|
|
|
public static function create(array $fields): FieldMap
|
|
{
|
|
return new FieldMap($fields);
|
|
}
|
|
|
|
public function __invoke($record): ?array
|
|
{
|
|
$new_record = [];
|
|
foreach ($this->_fields as $src=>$dst)
|
|
{
|
|
if (isset($record[$src]))
|
|
{
|
|
$new_record[$dst] = $record[$src];
|
|
}
|
|
}
|
|
return $new_record;
|
|
}
|
|
}
|
|
|