Skip to content

Commit

Permalink
Use transformation from importer in import. Minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathielen committed Apr 14, 2015
1 parent 762711c commit 0cdcd34
Show file tree
Hide file tree
Showing 7 changed files with 3,490 additions and 2,686 deletions.
3 changes: 2 additions & 1 deletion src/Mathielen/ImportEngine/Filter/Filters.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Mathielen\ImportEngine\Filter;

use Ddeboer\DataImport\Filter\FilterInterface;
use Ddeboer\DataImport\Workflow;

class Filters extends \ArrayObject
Expand All @@ -9,7 +10,7 @@ class Filters extends \ArrayObject
/**
* @return \Mathielen\ImportEngine\Filter\Filters
*/
public function add($filter)
public function add(FilterInterface $filter)
{
$this->append($filter);

Expand Down
2 changes: 1 addition & 1 deletion src/Mathielen/ImportEngine/Import/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(Importer $importer, StorageInterface $sourceStorage,
$this->importer = $importer;
$this->sourceStorage = $sourceStorage;
$this->importRun = $importRun;
$this->transformation = new Transformation();
$this->transformation = $importer->transformation();
}

/**
Expand Down
21 changes: 15 additions & 6 deletions src/Mathielen/ImportEngine/Mapping/DefaultMappingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@
class DefaultMappingFactory implements MappingFactoryInterface
{

/**
* @var Mappings
*/
private $mappings;

public function __construct(Mappings $mappings=null)
{
if (is_null($mappings)) {
$mappings = new Mappings();
}

$this->mappings = $mappings;
}

/**
* (non-PHPdoc)
* @see \Mathielen\ImportEngine\Mapping\MappingFactoryInterface::factor()
*/
public function factor(ReaderInterface $reader)
{
$mapping = new Mappings();

//foreach ($reader->getFields() as $field) {
//$mapping->addMapping($field, 'to', 'convert');
//}
return $mapping;
return $this->mappings;
}

}
14 changes: 10 additions & 4 deletions src/Mathielen/ImportEngine/Mapping/Mappings.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function add($from, $to, $converter=null)

public function setConverter($converter, $from=null)
{
if (!(is_string($converter) || $converter instanceof ValueConverterInterface || $converter instanceof ItemConverterInterface)) {
throw new \InvalidArgumentException("Converter must be an id (string) or of type ValueConverterInterface or ItemConverterInterface");
}

if ($from) {
$this->getOrCreateMapping($from)->converter = $converter;
} else {
Expand Down Expand Up @@ -82,14 +86,16 @@ public function apply(Workflow $workflow, array $converters)
}

if ($converter) {
if (!array_key_exists($converter, $converters)) {
throw new InvalidConfigurationException("Converter with id '$converter' not found in configured converters.");
if (is_string($converter)) {
if (!array_key_exists($converter, $converters)) {
throw new InvalidConfigurationException("Converter with id '$converter' not found in configured converters.");
}

$converter = $converters[$converter];
}

$converter = $converters[$converter];
if ($converter instanceof ValueConverterInterface) {
$workflow->addValueConverter($from, $converter);

} elseif ($converter instanceof ItemConverterInterface) {
$workflow->addItemConverter($converter);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mathielen/ImportEngine/Storage/ObjectStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct($classOrObjectFactory, JmsMetadataParser $metadataPa
} elseif (is_string($classOrObjectFactory)) {
$objectFactory = new DefaultObjectFactory($classOrObjectFactory);
} else {
throw \InvalidArgumentException("classOrObjectFactory must be of type string or ObjectFactoryInterface");
throw new \InvalidArgumentException("classOrObjectFactory must be of type string or ObjectFactoryInterface");
}

$this->objectFactory = $objectFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
use Mathielen\ImportEngine\Import\ImportBuilder;
use Mathielen\ImportEngine\Importer\ImporterRepository;
use Mathielen\ImportEngine\Storage\StorageLocator;
use Mathielen\ImportEngine\ValueObject\ImportConfiguration;
use Mathielen\ImportEngine\ValueObject\ImportRequest;
use Mathielen\ImportEngine\ValueObject\StorageSelection;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Finder\Finder;
use Mathielen\ImportEngine\Storage\Factory\FormatDiscoverLocalFileStorageFactory;
Expand Down
Loading

0 comments on commit 0cdcd34

Please sign in to comment.