Ejemplo n.º 1
0
 /**
  * {inheritDoc}
  */
 public function composeCompositeProperty(&$entity, ReflectionProperty $reflectionProperty, CompositeProperty $annotation)
 {
     /**
      * @var $annotation \Matmar10\Bundle\MoneyBundle\Annotation\Currency
      */
     $values = $this->getValues($entity, $reflectionProperty, $annotation);
     if (is_null($values['currencyCode'])) {
         return;
     }
     // build the currency instance from the currency manager using provided code
     $currencyInstance = $this->currencyManager->getCurrency($values['currencyCode']);
     // set the currency instance on the original entities field
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($entity, $currencyInstance);
 }
Ejemplo n.º 2
0
 public function composeCompositeProperty(&$entity, ReflectionProperty $reflectionProperty, CompositeProperty $annotation)
 {
     /**
      * @var $annotation \Matmar10\Bundle\MoneyBundle\Annotation\ExchangeRate
      */
     $values = $this->getValues($entity, $reflectionProperty, $annotation);
     if (is_null($values['fromCurrencyCode']) || is_null($values['toCurrencyCode']) || is_null($values['multiplier'])) {
         return;
     }
     // build the currency instance from the currency manager using provided code
     $fromCurrency = $this->currencyManager->getCurrency($values['fromCurrencyCode']);
     $toCurrency = $this->currencyManager->getCurrency($values['toCurrencyCode']);
     $className = $annotation->getClass();
     $exchangeRateInstance = new $className($fromCurrency, $toCurrency, $values['multiplier']);
     // set the currency instance on the original entities field
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($entity, $exchangeRateInstance);
 }
 public function testComposeCompositeProperties()
 {
     $entity = new AnnotatedTestEntity();
     // set Currency related fields
     $entity->setExampleCurrencyCode('BTC');
     $entity->exampleCurrencyUsingDefaultMapCurrencyCode = 'BTC';
     // set Money related fields
     $entity->setExampleMoneyAmountInteger(321);
     $entity->exampleMoneyUsingDefaultMapAmountInteger = 312;
     $entity->setExampleMoneyCurrencyCode('USD');
     $entity->exampleMoneyUsingDefaultMapCurrencyCode = 'USD';
     // set CurrencyPair related fields
     $entity->setExampleCurrencyPairFromCurrencyCode('GBP');
     $entity->exampleCurrencyPairUsingDefaultMapFromCurrencyCode = 'GBP';
     $entity->setExampleCurrencyPairToCurrencyCode('EUR');
     $entity->exampleCurrencyPairUsingDefaultMapToCurrencyCode = 'EUR';
     // set ExchangeRate related fields
     $entity->setExampleExchangeRateFromCurrencyCode('MAD');
     $entity->exampleExchangeRateUsingDefaultMapFromCurrencyCode = 'MAD';
     $entity->setExampleExchangeRateToCurrencyCode('JPY');
     $entity->exampleExchangeRateUsingDefaultMapToCurrencyCode = 'JPY';
     $entity->setExampleExchangeRateMultiplier(11.75);
     $entity->exampleExchangeRateUsingDefaultMapMultiplier = 11.75;
     // process the field mappings
     $this->compositePropertyService->composeCompositeProperties($entity);
     // test Currency
     $btc = $this->currencyManager->getCurrency('BTC');
     $this->assertEquals($btc, $entity->getExampleCurrency());
     // test Money
     $usdAmount = $this->currencyManager->getMoney('USD');
     $usdAmount->setAmountFloat(3.21);
     $this->assertEquals($usdAmount, $entity->getExampleMoney());
     // test CurrencyPair
     $gbp = $this->currencyManager->getCurrency('GBP');
     $eur = $this->currencyManager->getCurrency('EUR');
     $currencyPair = new CurrencyPair($gbp, $eur);
     $entity->setExampleCurrencyPair($currencyPair);
     $this->assertEquals($currencyPair, $entity->getExampleCurrencyPair());
     // test ExchangeRate
     $mad = $this->currencyManager->getCurrency('MAD');
     $jpy = $this->currencyManager->getCurrency('JPY');
     $exchangeRate = new ExchangeRate($mad, $jpy, 11.75);
     $entity->setExampleExchangeRate($exchangeRate);
     $this->assertEquals($exchangeRate, $entity->getExampleExchangeRate());
 }
Ejemplo n.º 4
0
 /**
  * @param string           $value
  * @param AbstractPlatform $platform
  *
  * @return \Matmar10\Money\Entity\Currency
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     return $this->currencyManager->getCurrency($value);
 }