Zend_Currency-Additional.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.currency.additional">
  4. <title>Additional informations on Zend_Currency</title>
  5. <sect2 id="zend.currency.additional.informations">
  6. <title>Currency informations</title>
  7. <para>
  8. Sometimes it is necessary to get informations which are related to a currency.
  9. <classname>Zend_Currency</classname> provides you with several methods to get this
  10. informations. Available methods include the following:
  11. </para>
  12. <itemizedlist mark='opencircle'>
  13. <listitem>
  14. <para>
  15. <emphasis><methodname>getCurrencyList()</methodname></emphasis>: Returns a list
  16. of all currencies which are used in the given region as array. Defaults to the
  17. objects locale when no region has been given.
  18. </para>
  19. </listitem>
  20. <listitem>
  21. <para>
  22. <emphasis><methodname>getLocale()</methodname></emphasis>: Returns the set
  23. locale for the actual currency.
  24. </para>
  25. </listitem>
  26. <listitem>
  27. <para>
  28. <emphasis><methodname>getName()</methodname></emphasis>: Returns the full name
  29. for the actual currency. When there is no full name available for the actual
  30. currency, it will return the abbreviation for it.
  31. </para>
  32. </listitem>
  33. <listitem>
  34. <para>
  35. <emphasis><methodname>getRegionList()</methodname></emphasis>: Returns a list
  36. of all regions where this currency is used as array. Defaults to the objects
  37. currency when no currency has been given.
  38. </para>
  39. </listitem>
  40. <listitem>
  41. <para>
  42. <emphasis><methodname>getService()</methodname></emphasis>: Returns the set
  43. exchange service object for the actual currency.
  44. </para>
  45. </listitem>
  46. <listitem>
  47. <para>
  48. <emphasis><methodname>getShortName()</methodname></emphasis>: Returns the
  49. abbreviation for the actual currency.
  50. </para>
  51. </listitem>
  52. <listitem>
  53. <para>
  54. <emphasis><methodname>getSymbol()</methodname></emphasis>: Returns the currency
  55. sign for the currency. When the currency has no symbol, then it will return the
  56. abbreviation for it.
  57. </para>
  58. </listitem>
  59. <listitem>
  60. <para>
  61. <emphasis><methodname>getValue()</methodname></emphasis>: Returns the set
  62. value for the actual currency.
  63. </para>
  64. </listitem>
  65. </itemizedlist>
  66. <para>
  67. Let's see some code snippets as example:
  68. </para>
  69. <programlisting language="php"><![CDATA[
  70. $currency = new Zend_Currency();
  71. var_dump($currency->getValue());
  72. // returns 0
  73. var_dump($currency->getRegionList());
  74. // could return an array with all regions where USD is used
  75. var_dump($currency->getRegionList('EUR'));
  76. // returns an array with all regions where EUR is used
  77. var_dump($currency->getName());
  78. // could return 'US Dollar'
  79. var_dump($currency->getName('EUR'));
  80. // returns 'Euro'
  81. ]]></programlisting>
  82. <para>
  83. As you can see, several methods allow to use additional parameters to override the
  84. actual object to get informations for other currencies. Omitting this parameters will
  85. return informations from the actual set currency.
  86. </para>
  87. </sect2>
  88. <sect2 id="zend.currency.additional.cache">
  89. <title>Currency Performance Optimization</title>
  90. <para>
  91. <classname>Zend_Currency</classname>'s performance can be optimized using
  92. <classname>Zend_Cache</classname>. The static method
  93. <methodname>Zend_Currency::setCache($cache)</methodname> accepts one option: a
  94. <classname>Zend_Cache</classname> adapter. If the cache adapter is set, the localization
  95. data which is used by <classname>Zend_Currency</classname> will be cached. Additionally
  96. there are some static methods for manipulating the cache:
  97. <methodname>getCache()</methodname>, <methodname>hasCache()</methodname>,
  98. <methodname>clearCache()</methodname> and <methodname>removeCache()</methodname>.
  99. </para>
  100. <example id="zend.currency.usage.cache.example">
  101. <title>Caching currencies</title>
  102. <programlisting language="php"><![CDATA[
  103. // creating a cache object
  104. $cache = Zend_Cache::factory('Core',
  105. 'File',
  106. array('lifetime' => 120,
  107. 'automatic_serialization' => true),
  108. array('cache_dir'
  109. => dirname(__FILE__) . '/_files/'));
  110. Zend_Currency::setCache($cache);
  111. ]]></programlisting>
  112. </example>
  113. </sect2>
  114. </sect1>