Skip to content

Commit

Permalink
fixed mapping
Browse files Browse the repository at this point in the history
new fieldlowercaseconverter
  • Loading branch information
mathielen committed Jun 20, 2015
1 parent 27b019c commit 745c147
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/Mathielen/DataImport/ItemConverter/FieldLowercaseConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace Mathielen\DataImport\ItemConverter;

use Ddeboer\DataImport\ItemConverter\ItemConverterInterface;

class FieldLowercaseConverter implements ItemConverterInterface
{

public function convert($input)
{
return array_change_key_case($input, CASE_LOWER);
}

}
2 changes: 1 addition & 1 deletion src/Mathielen/ImportEngine/Mapping/Mappings.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function apply(Workflow $workflow, ConverterProviderInterface $converterP
}

if ($converter instanceof ValueConverterInterface) {
$workflow->addValueConverter($from, $converter);
$workflow->addValueConverter($to, $converter);
} elseif ($converter instanceof ItemConverterInterface) {
$workflow->addItemConverter($converter);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mathielen/ImportEngine/Storage/LocalFileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private function formatToReader(Format $format, \SplFileInfo $file)
$reader = new CsvReader($file->openFile(), $format->getDelimiter(), $format->getEnclosure(), $format->getEscape());
$reader->setStrict(false);
if ($format->isHeaderInFirstRow()) {
$reader->setHeaderRowNumber(0);
$reader->setHeaderRowNumber(0, CsvReader::DUPLICATE_HEADERS_MERGE);
$reader->setColumnHeaders(array_map('trim', $reader->getColumnHeaders())); //TODO some header-collaborator?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public function test()
$import = $importBuilder->build($importRequest);

$import->mappings()
->add('Anrede', 'salutation', 'upperCase')
->add('Name', 'name', 'lowerCase');
->add('prefix', 'Anrede', 'upperCase')
->add('name', 'Name', 'lowerCase');

$importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher));

$expectedResult = array(
'name' => 'Jennie Abernathy',
'prefix' => 'Ms.',
'Name' => 'jennie abernathy',
'Anrede' => 'MS.',
'street' => '866 Hyatt Isle Apt. 888',
'zip' => '65982',
'city' => 'East Laurie',
Expand Down

0 comments on commit 745c147

Please sign in to comment.