Commit 063867e9 authored by Mike Ryan's avatar Mike Ryan

#58: Inject PropertyFactory to loaders.

parent c1ded782
Pipeline #58639930 passed with stage
in 2 minutes and 40 seconds
......@@ -101,8 +101,10 @@ class EtlCommand extends Command
$taskConfiguration['record_factory'] = $recordFactory;
$taskConfiguration['property_factory'] = $propertyFactory;
$taskConfiguration['extract']['configuration']['record_factory'] =
$taskConfiguration['record_factory'];
$recordFactory;
$taskConfiguration['extract'] = $this->getExtractor($taskConfiguration['extract'], $options);
$taskConfiguration['load']['configuration']['property_factory'] =
$propertyFactory;
$taskConfiguration['load'] = $this->getLoader($taskConfiguration['load']);
if (isset($taskConfiguration['key_map'])) {
$taskConfiguration['key_map'] = $this->getKeyMap(
......
......@@ -29,11 +29,10 @@ class Csv extends LoaderBase
*/
public function load(Record $data) : void
{
// @todo: Don't use concrete PropertyFactory class.
$propertyFactory = new PropertyFactory();
// @todo Should have a configuration option for this.
$data->setProperty(
array_keys($this->getConfigurationValue('key_properties'))[0],
$propertyFactory->create($this->counter++)
$this->getConfigurationValue('property_factory')->create($this->counter++)
);
$properties = $data->toArray();
if (count($properties) > 1) {
......
......@@ -46,9 +46,8 @@ class DBAL extends LoaderBase
$id = $this->connection()->lastInsertId();
if ($id) {
$keyKeys = array_keys($this->getKeyProperties());
// @todo: Don't use concrete PropertyFactory class.
$propertyFactory = new PropertyFactory();
$data->setProperty(reset($keyKeys), $propertyFactory->create($id));
$data->setProperty(reset($keyKeys),
$this->getConfigurationValue('property_factory')->create($id));
}
} catch (DBALException $e) {
print $e->getMessage();
......
......@@ -28,6 +28,10 @@ abstract class LoaderBase extends OptionsResolverComponent implements Loader
'default_value' => [],
'allowed_types' => 'array',
];
$options['property_factory'] = [
'required' => true,
'allowed_types' => 'Soong\Contracts\Data\PropertyFactory',
];
return $options;
}
......
......@@ -3,7 +3,6 @@
namespace Soong\Tests\Loader;
use Soong\Data\PropertyFactory;
use Soong\Data\Record;
use Soong\Data\RecordFactory;
use Soong\Tests\Contracts\Loader\LoaderTestBase;
......@@ -67,6 +66,8 @@ class CsvLoaderTest extends LoaderTestBase
return [
'key_properties' => $this->keyProperties(),
'properties' => array_keys($this->data()[0]),
// @todo Mock this
'property_factory' => new PropertyFactory(),
];
}
......
......@@ -101,6 +101,7 @@ class DBALLoaderTest extends LoaderTestBase
'configuration' => [
'table' => $dataSet['table_name'],
'key_properties' => $dataSet['key_properties'],
'property_factory' => $this->createMock(\Soong\Contracts\Data\PropertyFactory::class),
],
$dataSet['data'],
];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment