File indexing completed on 2025-03-02 05:29:58
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_View 0017 * @subpackage Helper 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** Zend_View_Helper_Abstract.php */ 0024 // require_once 'Zend/View/Helper/Abstract.php'; 0025 0026 /** 0027 * Currency view helper 0028 * 0029 * @category Zend 0030 * @package Zend_View 0031 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0032 * @license http://framework.zend.com/license/new-bsd New BSD License 0033 */ 0034 class Zend_View_Helper_Currency extends Zend_View_Helper_Abstract 0035 { 0036 /** 0037 * Currency object 0038 * 0039 * @var Zend_Currency 0040 */ 0041 protected $_currency; 0042 0043 /** 0044 * Constructor for manually handling 0045 * 0046 * @param Zend_Currency $currency Instance of Zend_Currency 0047 * @return void 0048 */ 0049 public function __construct($currency = null) 0050 { 0051 if ($currency === null) { 0052 // require_once 'Zend/Registry.php'; 0053 if (Zend_Registry::isRegistered('Zend_Currency')) { 0054 $currency = Zend_Registry::get('Zend_Currency'); 0055 } 0056 } 0057 0058 $this->setCurrency($currency); 0059 } 0060 0061 /** 0062 * Output a formatted currency 0063 * 0064 * @param integer|float $value Currency value to output 0065 * @param string|Zend_Locale|array $currency OPTIONAL Currency to use for 0066 * this call 0067 * @return string Formatted currency 0068 */ 0069 public function currency($value = null, $currency = null) 0070 { 0071 if ($value === null) { 0072 return $this; 0073 } 0074 0075 if (is_string($currency) || ($currency instanceof Zend_Locale)) { 0076 // require_once 'Zend/Locale.php'; 0077 if (Zend_Locale::isLocale($currency)) { 0078 $currency = array('locale' => $currency); 0079 } 0080 } 0081 0082 if (is_string($currency)) { 0083 $currency = array('currency' => $currency); 0084 } 0085 0086 if (is_array($currency)) { 0087 return $this->_currency->toCurrency($value, $currency); 0088 } 0089 0090 return $this->_currency->toCurrency($value); 0091 } 0092 0093 /** 0094 * Sets a currency to use 0095 * 0096 * @param Zend_Currency|String|Zend_Locale $currency Currency to use 0097 * @throws Zend_View_Exception When no or a false currency was set 0098 * @return Zend_View_Helper_Currency 0099 */ 0100 public function setCurrency($currency = null) 0101 { 0102 if (!$currency instanceof Zend_Currency) { 0103 // require_once 'Zend/Currency.php'; 0104 $currency = new Zend_Currency($currency); 0105 } 0106 $this->_currency = $currency; 0107 0108 return $this; 0109 } 0110 0111 /** 0112 * Retrieve currency object 0113 * 0114 * @return Zend_Currency|null 0115 */ 0116 public function getCurrency() 0117 { 0118 return $this->_currency; 0119 } 0120 }