Sometimes it is necessary to get informations which are related to a currency.
Zend_Currency
provides you with several methods to get this
informations. Available methods include the following:
-
getCurrencyList()
: Returns a list of all currencies which are used in the given region as array. Defaults to the objects locale when no region has been given. -
getLocale()
: Returns the set locale for the actual currency. -
getName()
: Returns the full name for the actual currency. When there is no full name available for the actual currency, it will return the abbreviation for it. -
getRegionList()
: Returns a list of all regions where this currency is used as array. Defaults to the objects currency when no currency has been given. -
getService()
: Returns the set exchange service object for the actual currency. -
getShortName()
: Returns the abbreviation for the actual currency. -
getSymbol()
: Returns the currency sign for the currency. When the currency has no symbol, then it will return the abbreviation for it. -
getValue()
: Returns the set value for the actual currency.
Let's see some code snippets as example:
$currency = new Zend_Currency(); var_dump($currency->getValue()); // returns 0 var_dump($currency->getRegionList()); // could return an array with all regions where USD is used var_dump($currency->getRegionList('EUR')); // returns an array with all regions where EUR is used var_dump($currency->getName()); // could return 'US Dollar' var_dump($currency->getName('EUR')); // returns 'Euro'
As you can see, several methods allow to use additional parameters to override the actual object to get informations for other currencies. Omitting this parameters will return informations from the actual set currency.
Zend_Currency
's performance can be optimized using
Zend_Cache
. The static method
Zend_Currency::setCache($cache)
accepts one option: a
Zend_Cache
adapter. If the cache adapter is set, the localization
data which is used by Zend_Currency
will be cached. Additionally
there are some static methods for manipulating the cache:
getCache()
, hasCache()
,
clearCache()
and removeCache()
.
例163 Caching currencies
// creating a cache object $cache = Zend_Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => dirname(__FILE__) . '/_files/')); Zend_Currency::setCache($cache);