$fileHandle =
fopen($filePath, 'rb'
);
if (!
$fileHandle) { throw new FileNotReadableException($filePath);
} // read the first CSV line
$record =
fgetcsv($fileHandle, 0,
$delimiter,
$enclosure,
$escape);
fclose($fileHandle);
if (empty($record) ||
$record[0
] === null
) { throw new InvalidFileContentException($file->
getFilename());
} // construct the mapping from the given CSV line data
$definition =
$this->definitionInstanceRegistry->
getByEntityName($sourceEntity);
$keyLookupTable =
$this->
getKeyLookupTable($context,
$sourceEntity);
$mappings =
new MappingCollection();
foreach ($record as $index =>
$column) { $mappings->
add(new Mapping( $this->
guessKeyFromMappedKey($keyLookupTable,
$column,
$definition),
$column,