Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_Currency Class Reference
Inheritance diagram for Zend_Currency:
Currency

Public Member Functions

 __construct ($options=null, $locale=null)
 
 toCurrency ($value=null, array $options=array())
 
 setFormat (array $options=array())
 
 getSymbol ($currency=null, $locale=null)
 
 getShortName ($currency=null, $locale=null)
 
 getName ($currency=null, $locale=null)
 
 getRegionList ($currency=null)
 
 getCurrencyList ($region=null)
 
 toString ()
 
 __toString ()
 
 setLocale ($locale=null)
 
 getLocale ()
 
 getValue ()
 
 setValue ($value, $currency=null)
 
 add ($value, $currency=null)
 
 sub ($value, $currency=null)
 
 div ($value, $currency=null)
 
 mul ($value, $currency=null)
 
 mod ($value, $currency=null)
 
 compare ($value, $currency=null)
 
 equals ($value, $currency=null)
 
 isMore ($value, $currency=null)
 
 isLess ($value, $currency=null)
 
 getService ()
 
 setService ($service)
 

Static Public Member Functions

static getCache ()
 
static setCache (Zend_Cache_Core $cache)
 
static hasCache ()
 
static removeCache ()
 
static clearCache ($tag=null)
 

Data Fields

const NO_SYMBOL = 1
 
const USE_SYMBOL = 2
 
const USE_SHORTNAME = 3
 
const USE_NAME = 4
 
const STANDARD = 8
 
const RIGHT = 16
 
const LEFT = 32
 

Protected Member Functions

 _exchangeCurrency ($value, $currency)
 
 _checkOptions (array $options=array())
 

Protected Attributes

 $_options
 

Detailed Description

Definition at line 37 of file Currency.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null,
  $locale = null 
)

Creates a currency instance. Every supressed parameter is used from the actual or the given locale.

Parameters
string | array$optionsOPTIONAL Options array or currency short name when string is given
string | Zend_Locale$localeOPTIONAL locale name
Exceptions
Zend_Currency_ExceptionWhen currency is invalid

Definition at line 92 of file Currency.php.

93  {
94  $calloptions = $options;
95  if (is_array($options) && isset($options['display'])) {
96  $this->_options['display'] = $options['display'];
97  }
98 
99  if (is_array($options)) {
100  $this->setLocale($locale);
101  $this->setFormat($options);
102  } else if (Zend_Locale::isLocale($options, false, false)) {
103  $this->setLocale($options);
104  $options = $locale;
105  } else {
106  $this->setLocale($locale);
107  }
108 
109  // Get currency details
110  if (!isset($this->_options['currency']) || !is_array($options)) {
111  $this->_options['currency'] = self::getShortName($options, $this->_options['locale']);
112  }
113 
114  if (!isset($this->_options['name']) || !is_array($options)) {
115  $this->_options['name'] = self::getName($options, $this->_options['locale']);
116  }
117 
118  if (!isset($this->_options['symbol']) || !is_array($options)) {
119  $this->_options['symbol'] = self::getSymbol($options, $this->_options['locale']);
120  }
121 
122  if (($this->_options['currency'] === null) and ($this->_options['name'] === null)) {
123  #require_once 'Zend/Currency/Exception.php';
124  throw new Zend_Currency_Exception("Currency '$options' not found");
125  }
126 
127  // Get the format
128  if ((is_array($calloptions) && !isset($calloptions['display']))
129  || (!is_array($calloptions) && $this->_options['display'] == self::NO_SYMBOL)) {
130  if (!empty($this->_options['symbol'])) {
131  $this->_options['display'] = self::USE_SYMBOL;
132  } else if (!empty($this->_options['currency'])) {
133  $this->_options['display'] = self::USE_SHORTNAME;
134  }
135  }
136  }
getName($currency=null, $locale=null)
Definition: Currency.php:404
const USE_SYMBOL
Definition: Currency.php:41
setLocale($locale=null)
Definition: Currency.php:552
getSymbol($currency=null, $locale=null)
Definition: Currency.php:341
setFormat(array $options=array())
Definition: Currency.php:290
getShortName($currency=null, $locale=null)
Definition: Currency.php:369
static isLocale($locale, $strict=false, $compatible=true)
Definition: Locale.php:1683
const USE_SHORTNAME
Definition: Currency.php:42

Member Function Documentation

◆ __toString()

__toString ( )

Returns the currency name

Returns
string

Definition at line 486 of file Currency.php.

487  {
488  return $this->toString();
489  }

◆ _checkOptions()

_checkOptions ( array  $options = array())
protected

Internal method for checking the options array

Parameters
array$optionsOptions to check
Exceptions
Zend_Currency_ExceptionOn unknown position
Zend_Currency_ExceptionOn unknown locale
Zend_Currency_ExceptionOn unknown display
Zend_Currency_ExceptionOn precision not between -1 and 30
Zend_Currency_ExceptionOn problem with script conversion
Zend_Currency_ExceptionOn unknown options
Returns
array

Definition at line 833 of file Currency.php.

834  {
835  if (count($options) === 0) {
836  return $this->_options;
837  }
838 
839  foreach ($options as $name => $value) {
840  $name = strtolower($name);
841  if ($name !== 'format') {
842  if (gettype($value) === 'string') {
843  $value = strtolower($value);
844  }
845  }
846 
847  switch($name) {
848  case 'position':
849  if (($value !== self::STANDARD) and ($value !== self::RIGHT) and ($value !== self::LEFT)) {
850  #require_once 'Zend/Currency/Exception.php';
851  throw new Zend_Currency_Exception("Unknown position '" . $value . "'");
852  }
853 
854  break;
855 
856  case 'format':
857  if ((empty($value) === false) and (Zend_Locale::isLocale($value, null, false) === false)) {
858  if (!is_string($value) || (strpos($value, '0') === false)) {
859  #require_once 'Zend/Currency/Exception.php';
860  throw new Zend_Currency_Exception("'" .
861  ((gettype($value) === 'object') ? get_class($value) : $value)
862  . "' is no format token");
863  }
864  }
865  break;
866 
867  case 'display':
868  if (is_numeric($value) and ($value !== self::NO_SYMBOL) and ($value !== self::USE_SYMBOL) and
869  ($value !== self::USE_SHORTNAME) and ($value !== self::USE_NAME)) {
870  #require_once 'Zend/Currency/Exception.php';
871  throw new Zend_Currency_Exception("Unknown display '$value'");
872  }
873  break;
874 
875  case 'precision':
876  if ($value === null) {
877  $value = -1;
878  }
879 
880  if (($value < -1) or ($value > 30)) {
881  #require_once 'Zend/Currency/Exception.php';
882  throw new Zend_Currency_Exception("'$value' precision has to be between -1 and 30.");
883  }
884  break;
885 
886  case 'script':
887  try {
889  } catch (Zend_Locale_Exception $e) {
890  #require_once 'Zend/Currency/Exception.php';
891  throw new Zend_Currency_Exception($e->getMessage());
892  }
893  break;
894 
895  default:
896  break;
897  }
898  }
899 
900  return $options;
901  }
static convertNumerals($input, $from, $to=null)
Definition: Format.php:198
$value
Definition: gender.phtml:16
static isLocale($locale, $strict=false, $compatible=true)
Definition: Locale.php:1683
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ _exchangeCurrency()

_exchangeCurrency (   $value,
  $currency 
)
protected

Internal method which calculates the exchanges currency

Parameters
float | integer | Zend_Currency$valueCompares the currency with this value
string | Zend_Currency$currencyThe currency to compare this value from
Returns
unknown

Definition at line 758 of file Currency.php.

759  {
760  if ($value instanceof Zend_Currency) {
761  $currency = $value->getShortName();
762  $value = $value->getValue();
763  } else {
764  $currency = $this->getShortName($currency, $this->getLocale());
765  }
766 
767  $rate = 1;
768  if ($currency !== $this->getShortName()) {
769  $service = $this->getService();
770  if (!($service instanceof Zend_Currency_CurrencyInterface)) {
771  #require_once 'Zend/Currency/Exception.php';
772  throw new Zend_Currency_Exception('No exchange service applied');
773  }
774 
775  $rate = $service->getRate($currency, $this->getShortName());
776  }
777 
778  $value *= $rate;
779  return $value;
780  }
getShortName($currency=null, $locale=null)
Definition: Currency.php:369
$value
Definition: gender.phtml:16

◆ add()

add (   $value,
  $currency = null 
)

Adds a currency

Parameters
float | integer | Zend_Currency$valueAdd this value to currency
string | Zend_Currency$currencyThe currency to add
Returns
Zend_Currency

Definition at line 616 of file Currency.php.

617  {
618  $value = $this->_exchangeCurrency($value, $currency);
619  $this->_options['value'] += (float) $value;
620  return $this;
621  }
_exchangeCurrency($value, $currency)
Definition: Currency.php:758
$value
Definition: gender.phtml:16

◆ clearCache()

static clearCache (   $tag = null)
static

Clears all set cache data

Parameters
string$tagTag to clear when the default tag name is not used
Returns
void

Definition at line 538 of file Currency.php.

539  {
541  }
static clearCache()
Definition: Data.php:1562

◆ compare()

compare (   $value,
  $currency = null 
)

Compares two currencies

Parameters
float | integer | Zend_Currency$valueCompares the currency with this value
string | Zend_Currency$currencyThe currency to compare this value from
Returns
Zend_Currency

Definition at line 686 of file Currency.php.

687  {
688  $value = $this->_exchangeCurrency($value, $currency);
689  $value = $this->_options['value'] - $value;
690  if ($value < 0) {
691  return -1;
692  } else if ($value > 0) {
693  return 1;
694  }
695 
696  return 0;
697  }
_exchangeCurrency($value, $currency)
Definition: Currency.php:758
$value
Definition: gender.phtml:16

◆ div()

div (   $value,
  $currency = null 
)

Divides a currency

Parameters
float | integer | Zend_Currency$valueDivides this value from currency
string | Zend_Currency$currencyThe currency to divide
Returns
Zend_Currency

Definition at line 644 of file Currency.php.

645  {
646  $value = $this->_exchangeCurrency($value, $currency);
647  $this->_options['value'] /= (float) $value;
648  return $this;
649  }
_exchangeCurrency($value, $currency)
Definition: Currency.php:758
$value
Definition: gender.phtml:16

◆ equals()

equals (   $value,
  $currency = null 
)

Returns true when the two currencies are equal

Parameters
float | integer | Zend_Currency$valueCompares the currency with this value
string | Zend_Currency$currencyThe currency to compare this value from
Returns
boolean

Definition at line 706 of file Currency.php.

707  {
708  $value = $this->_exchangeCurrency($value, $currency);
709  if ($this->_options['value'] == $value) {
710  return true;
711  }
712 
713  return false;
714  }
_exchangeCurrency($value, $currency)
Definition: Currency.php:758
$value
Definition: gender.phtml:16

◆ getCache()

static getCache ( )
static

Returns the set cache

Returns
Zend_Cache_Core The set cache

Definition at line 496 of file Currency.php.

497  {
499  }
static getCache()
Definition: Data.php:1517

◆ getCurrencyList()

getCurrencyList (   $region = null)

Returns a list of currencies which are used in this region a region name should be 2 charachters only (f.e. EG, DE, US) If no region is given, the actual region is used

Parameters
string$regionOPTIONAL Region to return the currencies for
Returns
array List of currencies

Definition at line 457 of file Currency.php.

458  {
459  if (empty($region) === true) {
460  if (strlen($this->_options['locale']) > 4) {
461  $region = substr($this->_options['locale'], (strpos($this->_options['locale'], '_') + 1));
462  }
463  }
464 
465  $data = Zend_Locale_Data::getContent($this->_options['locale'], 'currencytoregion', $region);
466 
467  $result = explode(' ', $data);
468  return $result;
469  }
static getContent($locale, $path, $value=false)
Definition: Data.php:968

◆ getLocale()

getLocale ( )

Returns the actual set locale

Returns
string

Definition at line 581 of file Currency.php.

582  {
583  return $this->_options['locale'];
584  }

◆ getName()

getName (   $currency = null,
  $locale = null 
)

Returns the actual or details of other currency names

Parameters
string$currency(Optional) Currency's short name
string | Zend_Locale$locale(Optional) The locale
Returns
string

Definition at line 404 of file Currency.php.

405  {
406  if (($currency === null) and ($locale === null)) {
407  return $this->_options['name'];
408  }
409 
410  $params = self::_checkParams($currency, $locale);
411 
412  // Get the name
413  $name = Zend_Locale_Data::getContent($params['locale'], 'nametocurrency', $params['currency']);
414  if (empty($name) === true) {
415  $name = Zend_Locale_Data::getContent($params['locale'], 'nametocurrency', $params['name']);
416  }
417 
418  if (empty($name) === true) {
419  return null;
420  }
421 
422  return $name;
423  }
static getContent($locale, $path, $value=false)
Definition: Data.php:968
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getRegionList()

getRegionList (   $currency = null)

Returns a list of regions where this currency is or was known

Parameters
string$currencyOPTIONAL Currency's short name
Exceptions
Zend_Currency_ExceptionWhen no currency was defined
Returns
array List of regions

Definition at line 432 of file Currency.php.

433  {
434  if ($currency === null) {
435  $currency = $this->_options['currency'];
436  }
437 
438  if (empty($currency) === true) {
439  #require_once 'Zend/Currency/Exception.php';
440  throw new Zend_Currency_Exception('No currency defined');
441  }
442 
443  $data = Zend_Locale_Data::getContent($this->_options['locale'], 'regiontocurrency', $currency);
444 
445  $result = explode(' ', $data);
446  return $result;
447  }
static getContent($locale, $path, $value=false)
Definition: Data.php:968

◆ getService()

getService ( )

Returns the set service class

Returns
Zend_Service

Definition at line 787 of file Currency.php.

788  {
789  return $this->_options['service'];
790  }

◆ getShortName()

getShortName (   $currency = null,
  $locale = null 
)

Returns the actual or details of other currency shortnames

Parameters
string$currencyOPTIONAL Currency's name
string | Zend_Locale$localeOPTIONAL The locale
Returns
string

Definition at line 369 of file Currency.php.

370  {
371  if (($currency === null) and ($locale === null)) {
372  return $this->_options['currency'];
373  }
374 
375  $params = self::_checkParams($currency, $locale);
376 
377  // Get the shortname
378  if (empty($params['currency']) === true) {
379  return $params['name'];
380  }
381 
382  $list = Zend_Locale_Data::getContent($params['locale'], 'currencytoname', $params['currency']);
383  if (empty($list) === true) {
384  $list = Zend_Locale_Data::getContent($params['locale'], 'nametocurrency', $params['currency']);
385  if (empty($list) === false) {
386  $list = $params['currency'];
387  }
388  }
389 
390  if (empty($list) === true) {
391  return null;
392  }
393 
394  return $list;
395  }
static getContent($locale, $path, $value=false)
Definition: Data.php:968
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getSymbol()

getSymbol (   $currency = null,
  $locale = null 
)

Returns the actual or details of other currency symbols, when no symbol is available it returns the currency shortname (f.e. FIM for Finnian Mark)

Parameters
string$currency(Optional) Currency name
string | Zend_Locale$locale(Optional) Locale to display informations
Returns
string

Definition at line 341 of file Currency.php.

342  {
343  if (($currency === null) and ($locale === null)) {
344  return $this->_options['symbol'];
345  }
346 
347  $params = self::_checkParams($currency, $locale);
348 
349  // Get the symbol
350  $symbol = Zend_Locale_Data::getContent($params['locale'], 'currencysymbol', $params['currency']);
351  if (empty($symbol) === true) {
352  $symbol = Zend_Locale_Data::getContent($params['locale'], 'currencysymbol', $params['name']);
353  }
354 
355  if (empty($symbol) === true) {
356  return null;
357  }
358 
359  return $symbol;
360  }
static getContent($locale, $path, $value=false)
Definition: Data.php:968
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getValue()

getValue ( )

Returns the value

Returns
float

Definition at line 591 of file Currency.php.

592  {
593  return $this->_options['value'];
594  }

◆ hasCache()

static hasCache ( )
static

Returns true when a cache is set

Returns
boolean

Definition at line 517 of file Currency.php.

518  {
520  }
static hasCache()
Definition: Data.php:1538

◆ isLess()

isLess (   $value,
  $currency = null 
)

Returns true when the currency is less than the given value

Parameters
float | integer | Zend_Currency$valueCompares the currency with this value
string | Zend_Currency$currencyThe currency to compare this value from
Returns
boolean

Definition at line 740 of file Currency.php.

741  {
742  $value = $this->_exchangeCurrency($value, $currency);
743  if ($this->_options['value'] < $value) {
744  return true;
745  }
746 
747  return false;
748 
749  }
_exchangeCurrency($value, $currency)
Definition: Currency.php:758
$value
Definition: gender.phtml:16

◆ isMore()

isMore (   $value,
  $currency = null 
)

Returns true when the currency is more than the given value

Parameters
float | integer | Zend_Currency$valueCompares the currency with this value
string | Zend_Currency$currencyThe currency to compare this value from
Returns
boolean

Definition at line 723 of file Currency.php.

724  {
725  $value = $this->_exchangeCurrency($value, $currency);
726  if ($this->_options['value'] > $value) {
727  return true;
728  }
729 
730  return false;
731  }
_exchangeCurrency($value, $currency)
Definition: Currency.php:758
$value
Definition: gender.phtml:16

◆ mod()

mod (   $value,
  $currency = null 
)

Calculates the modulo from a currency

Parameters
float | integer | Zend_Currency$valueCalculate modulo from this value
string | Zend_Currency$currencyThe currency to calculate the modulo
Returns
Zend_Currency

Definition at line 672 of file Currency.php.

673  {
674  $value = $this->_exchangeCurrency($value, $currency);
675  $this->_options['value'] %= (float) $value;
676  return $this;
677  }
_exchangeCurrency($value, $currency)
Definition: Currency.php:758
$value
Definition: gender.phtml:16

◆ mul()

mul (   $value,
  $currency = null 
)

Multiplies a currency

Parameters
float | integer | Zend_Currency$valueMultiplies this value from currency
string | Zend_Currency$currencyThe currency to multiply
Returns
Zend_Currency

Definition at line 658 of file Currency.php.

659  {
660  $value = $this->_exchangeCurrency($value, $currency);
661  $this->_options['value'] *= (float) $value;
662  return $this;
663  }
_exchangeCurrency($value, $currency)
Definition: Currency.php:758
$value
Definition: gender.phtml:16

◆ removeCache()

static removeCache ( )
static

Removes any set cache

Returns
void

Definition at line 527 of file Currency.php.

528  {
530  }
static removeCache()
Definition: Data.php:1552

◆ setCache()

static setCache ( Zend_Cache_Core  $cache)
static

Sets a cache for Zend_Currency

Parameters
Zend_Cache_Core$cacheCache to set
Returns
void

Definition at line 507 of file Currency.php.

508  {
510  }
static setCache(Zend_Cache_Core $cache)
Definition: Data.php:1527

◆ setFormat()

setFormat ( array  $options = array())

Sets the formating options of the localized currency string If no parameter is passed, the standard setting of the actual set locale will be used

Parameters
array$options(Optional) Options to set
Returns
Zend_Currency

Definition at line 290 of file Currency.php.

291  {
292  $this->_options = $this->_checkOptions($options) + $this->_options;
293  return $this;
294  }
_checkOptions(array $options=array())
Definition: Currency.php:833

◆ setLocale()

setLocale (   $locale = null)

Sets a new locale for data retreivement Example: 'de_XX' will be set to 'de' because 'de_XX' does not exist 'xx_YY' will be set to 'root' because 'xx' does not exist

Parameters
string | Zend_Locale$locale(Optional) Locale for parsing input
Exceptions
Zend_Currency_ExceptionWhen the given locale does not exist
Returns
Zend_Currency Provides fluent interface

Definition at line 552 of file Currency.php.

553  {
554  #require_once 'Zend/Locale.php';
555  try {
556  $locale = Zend_Locale::findLocale($locale);
557  if (strlen($locale) > 4) {
558  $this->_options['locale'] = $locale;
559  } else {
560  #require_once 'Zend/Currency/Exception.php';
561  throw new Zend_Currency_Exception("No region found within the locale '" . (string) $locale . "'");
562  }
563  } catch (Zend_Locale_Exception $e) {
564  #require_once 'Zend/Currency/Exception.php';
565  throw new Zend_Currency_Exception($e->getMessage());
566  }
567 
568  // Get currency details
569  $this->_options['currency'] = $this->getShortName(null, $this->_options['locale']);
570  $this->_options['name'] = $this->getName(null, $this->_options['locale']);
571  $this->_options['symbol'] = $this->getSymbol(null, $this->_options['locale']);
572 
573  return $this;
574  }
getName($currency=null, $locale=null)
Definition: Currency.php:404
getSymbol($currency=null, $locale=null)
Definition: Currency.php:341
getShortName($currency=null, $locale=null)
Definition: Currency.php:369
static findLocale($locale=null)
Definition: Locale.php:1740

◆ setService()

setService (   $service)

Sets a new exchange service

Parameters
string | Zend_Currency_CurrencyInterface$serviceService class
Returns
Zend_Currency

Definition at line 798 of file Currency.php.

799  {
800  if (is_string($service)) {
801  #require_once 'Zend/Loader.php';
802  if (!class_exists($service)) {
803  $file = str_replace('_', DIRECTORY_SEPARATOR, $service) . '.php';
804  if (Zend_Loader::isReadable($file)) {
806  }
807  }
808 
809  $service = new $service;
810  }
811 
812  if (!($service instanceof Zend_Currency_CurrencyInterface)) {
813  #require_once 'Zend/Currency/Exception.php';
814  throw new Zend_Currency_Exception('A currency service must implement Zend_Currency_CurrencyInterface');
815  }
816 
817  $this->_options['service'] = $service;
818  return $this;
819  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52
static isReadable($filename)
Definition: Loader.php:162

◆ setValue()

setValue (   $value,
  $currency = null 
)

Adds a currency

Parameters
float | integer | Zend_Currency$valueAdd this value to currency
string | Zend_Currency$currencyThe currency to add
Returns
Zend_Currency

Definition at line 603 of file Currency.php.

604  {
605  $this->_options['value'] = $this->_exchangeCurrency($value, $currency);
606  return $this;
607  }
_exchangeCurrency($value, $currency)
Definition: Currency.php:758
$value
Definition: gender.phtml:16

◆ sub()

sub (   $value,
  $currency = null 
)

Substracts a currency

Parameters
float | integer | Zend_Currency$valueSubstracts this value from currency
string | Zend_Currency$currencyThe currency to substract
Returns
Zend_Currency

Definition at line 630 of file Currency.php.

631  {
632  $value = $this->_exchangeCurrency($value, $currency);
633  $this->_options['value'] -= (float) $value;
634  return $this;
635  }
_exchangeCurrency($value, $currency)
Definition: Currency.php:758
$value
Definition: gender.phtml:16

◆ toCurrency()

toCurrency (   $value = null,
array  $options = array() 
)

Returns a localized currency string

Parameters
integer | float$valueOPTIONAL Currency value
array$optionsOPTIONAL options to set temporary
Exceptions
Zend_Currency_ExceptionWhen the value is not a number
Returns
string

Definition at line 146 of file Currency.php.

147  {
148  if ($value === null) {
149  if (is_array($options) && isset($options['value'])) {
150  $value = $options['value'];
151  } else {
152  $value = $this->_options['value'];
153  }
154  }
155 
156  if (is_array($value)) {
157  $options += $value;
158  if (isset($options['value'])) {
159  $value = $options['value'];
160  }
161  }
162 
163  // Validate the passed number
164  if (!(isset($value)) or (is_numeric($value) === false)) {
165  #require_once 'Zend/Currency/Exception.php';
166  throw new Zend_Currency_Exception("Value '$value' has to be numeric");
167  }
168 
169  if (isset($options['currency'])) {
170  if (!isset($options['locale'])) {
171  $options['locale'] = $this->_options['locale'];
172  }
173 
174  $options['currency'] = self::getShortName($options['currency'], $options['locale']);
175  $options['name'] = self::getName($options['currency'], $options['locale']);
176  $options['symbol'] = self::getSymbol($options['currency'], $options['locale']);
177  }
178 
180 
181  // Format the number
182  $format = $options['format'];
183  $locale = $options['locale'];
184  if (empty($format)) {
185  $format = Zend_Locale_Data::getContent($locale, 'currencynumber');
186  } else if (Zend_Locale::isLocale($format, true, false)) {
187  $locale = $format;
188  $format = Zend_Locale_Data::getContent($format, 'currencynumber');
189  }
190 
191  $original = $value;
192  $value = Zend_Locale_Format::toNumber($value, array('locale' => $locale,
193  'number_format' => $format,
194  'precision' => $options['precision']));
195 
196  if ($options['position'] !== self::STANDARD) {
197  $value = str_replace('¤', '', $value);
198  $space = '';
199  if (iconv_strpos($value, ' ') !== false) {
200  $value = str_replace(' ', '', $value);
201  $space = ' ';
202  }
203 
204  if ($options['position'] == self::LEFT) {
205  $value = '¤' . $space . $value;
206  } else {
207  $value = $value . $space . '¤';
208  }
209  }
210 
211  // Localize the number digits
212  if (empty($options['script']) === false) {
214  }
215 
216  // Get the sign to be placed next to the number
217  if (is_numeric($options['display']) === false) {
218  $sign = $options['display'];
219  } else {
220  switch($options['display']) {
221  case self::USE_SYMBOL:
222  $sign = $this->_extractPattern($options['symbol'], $original);
223  break;
224 
225  case self::USE_SHORTNAME:
226  $sign = $options['currency'];
227  break;
228 
229  case self::USE_NAME:
230  $sign = $options['name'];
231  break;
232 
233  default:
234  $sign = '';
235  $value = str_replace(' ', '', $value);
236  break;
237  }
238  }
239 
240  $value = str_replace('¤', $sign, $value);
241  return $value;
242  }
getName($currency=null, $locale=null)
Definition: Currency.php:404
const USE_SYMBOL
Definition: Currency.php:41
static getContent($locale, $path, $value=false)
Definition: Data.php:968
getSymbol($currency=null, $locale=null)
Definition: Currency.php:341
const USE_NAME
Definition: Currency.php:43
getShortName($currency=null, $locale=null)
Definition: Currency.php:369
static convertNumerals($input, $from, $to=null)
Definition: Format.php:198
$value
Definition: gender.phtml:16
$format
Definition: list.phtml:12
_checkOptions(array $options=array())
Definition: Currency.php:833
static isLocale($locale, $strict=false, $compatible=true)
Definition: Locale.php:1683
static toNumber($value, array $options=array())
Definition: Format.php:300
const USE_SHORTNAME
Definition: Currency.php:42

◆ toString()

toString ( )

Returns the actual currency name

Returns
string

Definition at line 476 of file Currency.php.

477  {
478  return $this->toCurrency();
479  }
toCurrency($value=null, array $options=array())
Definition: Currency.php:146

Field Documentation

◆ $_options

$_options
protected
Initial value:
= array(
'position' => self::STANDARD,
'script' => null,
'format' => null,
'display' => self::NO_SYMBOL,
'precision' => 2,
'name' => null,
'currency' => null,
'symbol' => null,
'locale' => null,
'value' => 0,
'service' => null,
'tag' => 'Zend_Locale'
)

Definition at line 69 of file Currency.php.

◆ LEFT

const LEFT = 32

Definition at line 48 of file Currency.php.

◆ NO_SYMBOL

const NO_SYMBOL = 1

Definition at line 40 of file Currency.php.

◆ RIGHT

const RIGHT = 16

Definition at line 47 of file Currency.php.

◆ STANDARD

const STANDARD = 8

Definition at line 46 of file Currency.php.

◆ USE_NAME

const USE_NAME = 4

Definition at line 43 of file Currency.php.

◆ USE_SHORTNAME

const USE_SHORTNAME = 3

Definition at line 42 of file Currency.php.

◆ USE_SYMBOL

const USE_SYMBOL = 2

Definition at line 41 of file Currency.php.


The documentation for this class was generated from the following file: