本文整理汇总了PHP中Currency::getCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Currency::getCode方法的具体用法?PHP Currency::getCode怎么用?PHP Currency::getCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Currency
的用法示例。
在下文中一共展示了Currency::getCode方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConversionMultiplier
/**
* @param Currency $from
* @param Currency $to
* @return string
* @throws \RuntimeException
*/
public function getConversionMultiplier(Currency $from, Currency $to)
{
$rates = $this->getConversionRatesTable($from);
if (!isset($rates[$to->getCode()])) {
throw new \RuntimeException(sprintf('The target currency "%s" is not present in the conversion rates table.', $to->getCode()));
}
return $rates[$to->getCode()];
}
示例2: contains
/**
* {@inheritdoc}
*/
public function contains(Currency $currency)
{
if (null === self::$currencies) {
self::$currencies = $this->requireCurrencies();
}
return array_key_exists($currency->getCode(), self::$currencies);
}
示例3: edit
/**
* Update existing route
*
* @param void
* @return null
*/
function edit()
{
if ($this->active_currency->isNew()) {
$this->httpError(HTTP_ERR_NOT_FOUND);
}
// if
$currency_data = $this->request->post('currency');
if (!is_array($currency_data)) {
$currency_data = array('name' => $this->active_currency->getName(), 'code' => $this->active_currency->getCode(), 'default_rate' => $this->active_currency->getDefaultRate());
}
// if
$this->smarty->assign('currency_data', $currency_data);
if ($this->request->isSubmitted()) {
$this->active_currency->setAttributes($currency_data);
$save = $this->active_currency->save();
if ($save && !is_error($save)) {
flash_success('Currency ":name" has been updated', array('name' => $this->active_currency->getName()));
$this->redirectTo('admin_currencies');
} else {
$this->smarty->assign('errors', $save);
}
// if
}
// if
}
示例4: getConversionRatesTable
/**
* @param Currency $currency
* @return array
*/
public function getConversionRatesTable(Currency $currency)
{
switch ($currency->getCode()) {
case 'USD':
return array('USD' => '1', 'ZAR' => '12.07682');
default:
// ZAR
return array('USD' => '0.082776', 'ZAR' => '1');
}
}
示例5: compare
/**
* @param Money|string|int|float $money
* @return int
* @throws CurrencyMismatchException
*/
public function compare($money)
{
if ($money instanceof Money) {
if (!$this->isSameCurrencyAs($money)) {
throw new CurrencyMismatchException(sprintf('The monetary values being compared must be of the same currency (%s !== %s).', $this->currency->getCode(), $money->getCurrency()->getCode()));
}
}
$amount = Utils::toStringAmount($money);
return bccomp($this->amount, $amount, $this->scaleFactor);
}
示例6: getConversionRatesTable
/**
* @param Currency $currency
* @return array
* @throws \RuntimeException
*/
public function getConversionRatesTable(Currency $currency)
{
$ch = curl_init();
$url = sprintf('http://openexchangerates.org/api/latest.json?app_id=%s', $this->appId);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if ($response === false) {
throw new \RuntimeException(sprintf('An error occurred querying %s for conversion rates - (%s - %d)', $url, curl_error($ch), curl_errno($ch)));
}
$result = json_decode($response, true);
if (is_array($result) && isset($result['rates'])) {
$rates = $result['rates'];
// the free plan only supports a base currency of 'usd'
// we therefore need to convert the table to our own base currency
// first, our own base must be present in the conversion table
if (!isset($rates[$currency->getCode()])) {
return array();
// nothing more to do
}
$usd2base = (string) $rates[$currency->getCode()];
$table = array();
foreach ($rates as $code => $rate) {
if ($code === 'USD') {
$table[$code] = '1';
} else {
$rate = (string) $rate;
$multiplier = bcdiv('1', $usd2base, 6);
$table[$code] = bcmul($rate, $multiplier, 6);
}
}
return $table;
} else {
return array();
// response isn't what we expected / missing rates
}
}
示例7: testConstruct
/**
* @depends testSetCode
* @depends testSetCodeWithExceptionThrown
*/
public function testConstruct()
{
$currency = new Currency('usd');
$this->assertSame('USD', $currency->getCode());
}
示例8: getRateFromXML
public function getRateFromXML(Currency $from, Currency $to, SimpleXMLElement $xml)
{
$item = $xml->xpath('/rss/channel/item[title="' . $to->getCode() . '/' . $from->getCode() . '"]');
$item = is_array($item) ? current($item) : false;
if ($item instanceof SimpleXMLElement) {
preg_match('/= ([0-9]+\\.?[0-9]*) /', $item->description, $matches);
}
return isset($matches[1]) ? $matches[1] : false;
}
示例9: compareCurrency
/**
* @param Money $otherMoney
*
* @throws CurrencyMismatchException
*/
private function compareCurrency(Money $otherMoney)
{
if ($this->currency->compareTo($otherMoney->getCurrency()) !== 0) {
throw CurrencyMismatchException::currenciesNotMatching($this->currency->getCode(), $otherMoney->getCurrency()->getCode());
}
}
示例10: equals
/**
* Whether this and another currency are the same. Uses only the code to determine identity.
*
* @param Currency $currency the currency to compare to
*
* @return boolean true if the currency codes match, false otherwise
*/
public function equals(Currency $currency)
{
return $this->code == $currency->getCode();
}
示例11: findOneByFromCodeAndToCode
public function findOneByFromCodeAndToCode(Currency $from, Currency $to)
{
return Doctrine_Query::create()->from('CurrencyRate')->where('from_code = ?', $from->getCode())->andWhere('to_code = ?', $to->getCode())->fetchOne();
}
示例12: compareTo
/**
* @param Currency $otherCurrency
*
* @return int
*/
public function compareTo(Currency $otherCurrency)
{
return strcmp($this->code, $otherCurrency->getCode());
}
示例13: isEqualTo
/**
* @param Currency $currency
*
* @return bool
*/
public function isEqualTo(Currency $currency)
{
return $this->getCode() === $currency->getCode();
}
示例14: setCurrency
/**
* @param Currency $currency this field is required for partial refunds.
* Do not use this field for full refunds.
*/
public function setCurrency(Currency $currency)
{
$this->collection->setValue('CURRENCYCODE', $currency->getCode());
}