Skip to content

Commit

Permalink
[ENH] add option to currencyColumn to sepcify currency path
Browse files Browse the repository at this point in the history
  • Loading branch information
n3o77 committed Oct 30, 2023
1 parent a5423b6 commit db8f2d1
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/ColumnType/CurrencyColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,34 @@ public function configureOptions(OptionsResolver $resolver): void

$resolver->setDefaults([
'currency' => 'EUR',
'currency_path' => null,
'divider' => 0,
]);

$resolver->setAllowedTypes('currency', ['string']);
$resolver->setAllowedTypes('currency', ['string', 'null']);
$resolver->setAllowedTypes('currency_path', ['string', 'null']);

$resolver->setAllowedValues('currency', Currencies::getCurrencyCodes());
}

public function getValue(string $field, object $object, array $options = [])
{
$value = parent::getValue($field, $object, $options);

if ($options['divider'] > 0) {
$value /= $options['divider'];
}

return $value;
}

public function getCurrency(object $object, array $options)
{
if ($options['currency_path']) {
return $this->propertyAccessor->getValue($object, $options['currency_path']);
}

return $options['currency'];
}

}

0 comments on commit db8f2d1

Please sign in to comment.