Skip to content

Commit

Permalink
Support custom field mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
puleeno committed May 25, 2022
1 parent 6ddc327 commit ac22cd1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Abstracts/Tooth.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function addMappingField($fieldName, $args)
'pattern' => '',
));

if ($args['type'] && (($args['type'] != 'guid' && $args['pattern']) || $args['type'] == 'guid')) {
if ($args['type'] && (!empty($args['pattern']) || in_array($args['type'], array('guid', 'custom')))) {
$this->mappingFields[$fieldName] = $args;
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/DataSource/FeedItemBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public function build()
$mappingField->getSource(),
$mappingField
);
} elseif ($mappingField->getSourceType() === 'custom') {
$value = $this->getCustomValue(
$mappingField->getSource(),
$mappingField
);
} elseif ($mappingField->getSourceType() === 'guid') {
$value = $this->getGuidValue(
$mappingField->getSource(),
Expand Down Expand Up @@ -260,6 +265,14 @@ public function setGuid($guid)
$this->guid = $guid;
}

/**
* @var \Ramphor\Rake\DataSource\FieldMapping $mappingField
*/
public function getCustomValue($attribute, $mappingField)
{
return $mappingField->getDefaultValue();
}


public function getGuidValue($attribute, $mappingField)
{
Expand Down
2 changes: 1 addition & 1 deletion src/DataSource/FieldMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class FieldMapping
{
protected static $supportedSourceTypes = ["xpath", "dom", "regex", "attribute", "guid"];
protected static $supportedSourceTypes = ['xpath', 'dom', 'regex', 'attribute', 'guid', 'custom'];

protected $sourceField;
protected $destField;
Expand Down

0 comments on commit ac22cd1

Please sign in to comment.