Ignore:
Timestamp:
Nov 24, 2015 5:38:54 PM (8 years ago)
Author:
anonymous
Message:

Escaped quotes from email from names.
Changed logMsg string truncation method and added version to email log msg.
Better variable testing in carry queries.
Spelling errors.
Added runtime cache to Currency.
Added logging to form validation.
More robust form validation.
Added json serialization methond to Version.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Currency.inc.php

    r502 r550  
    4040class Currency
    4141{
    42 
    4342    // Configuration parameters for this object.
    4443    protected $_params = array(
     
    4948        'api_key' => '', // Used only by xurrency API.
    5049    );
     50
     51    // Static runtime cache of values.
     52    private static $rates = array();
    5153
    5254    /**
     
    143145        $app =& App::getInstance();
    144146
     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
    145154        $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        }
    146158        $cache_file_mtime = @filemtime($cache_file_path);
    147159        if (!$this->getParam('cache_result') || !$cache_file_mtime || $cache_file_mtime < time() - $this->getParam('cache_age')) {
     
    172184        }
    173185        $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
    174190        return trim($value);
    175191    }
     
    239255                return (float) $aCurrencies[$parameters['base']][$parameters['target']];
    240256            } 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__);
    242258                return false;
    243259            }
    244260
    245261        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;
    249264        }
    250265    }
Note: See TracChangeset for help on using the changeset viewer.