Changeset 550 for trunk/lib/Currency.inc.php
- Timestamp:
- Nov 24, 2015 5:38:54 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Currency.inc.php
r502 r550 40 40 class Currency 41 41 { 42 43 42 // Configuration parameters for this object. 44 43 protected $_params = array( … … 49 48 'api_key' => '', // Used only by xurrency API. 50 49 ); 50 51 // Static runtime cache of values. 52 private static $rates = array(); 51 53 52 54 /** … … 143 145 $app =& App::getInstance(); 144 146 147 // If we've looked-up this rate during this run, return it from the runtime cache. 148 $rate_key = sprintf('%s-to-%s', $base, $target); 149 if (isset(self::$rates[$rate_key])) { 150 $app->logMsg(sprintf('Found %s in runtime cache: %s', $rate_key, self::$rates[$rate_key]), LOG_DEBUG, __FILE__, __LINE__); 151 return self::$rates[$rate_key]; 152 } 153 145 154 $cache_file_path = sprintf('%s/%s-to-%s', $this->getParam('cache_dir'), $base, $target); 155 if (!is_dir(dirname($cache_file_path))) { 156 mkdir(dirname($cache_file_path)); 157 } 146 158 $cache_file_mtime = @filemtime($cache_file_path); 147 159 if (!$this->getParam('cache_result') || !$cache_file_mtime || $cache_file_mtime < time() - $this->getParam('cache_age')) { … … 172 184 } 173 185 $app->logMsg(sprintf('Found currency exchange rate: %s-to-%s = %s', $base, $target, $value), LOG_DEBUG, __FILE__, __LINE__); 186 187 // Store the value in the runtime cache. 188 self::$rates[$rate_key] = trim($value); 189 174 190 return trim($value); 175 191 } … … 239 255 return (float) $aCurrencies[$parameters['base']][$parameters['target']]; 240 256 } else { 241 $app->logMsg(sprintf('API %s does not have base %s or target %s', $this->getParam('api'), $parameters['base'], $parameters['target']), LOG_ WARNING, __FILE__, __LINE__);257 $app->logMsg(sprintf('API %s does not have base %s or target %s', $this->getParam('api'), $parameters['base'], $parameters['target']), LOG_ALERT, __FILE__, __LINE__); 242 258 return false; 243 259 } 244 260 245 261 default : 246 trigger_error('Unknown API: ' . $this->getParam('api'), E_USER_ERROR); 247 die; 248 break; 262 $app->logMsg(sprintf('Unknown currency API: %s', $this->getParam('api')), LOG_ERR, __FILE__, __LINE__); 263 return false; 249 264 } 250 265 }
Note: See TracChangeset
for help on using the changeset viewer.