Services_ExchangeRates
[ class tree: Services_ExchangeRates ] [ index: Services_ExchangeRates ] [ all elements ]

Class: Services_ExchangeRates

Source Location: /Services_ExchangeRates-0.5.3/ExchangeRates.php

Class Overview


Exchange Rate package


Author(s):

Copyright:

  • Copyright 2003 Marshall Roch

Methods


Inherited Variables

Inherited Methods


Class Details

[line 63]
Exchange Rate package

This package converts back and forth between different currencies, in any combination. All data used is updated automatically from interchangable sources. That is, if there is a source publishing exchange rates that isn't supported yet, you could write a driver and use that source seamlessly with the rest of the package.

Disclaimer: The rates are nominal quotations - neither buying nor selling rates - and are intended for statistical or analytical purposes. Rates available from financial institutions will differ.

The United Nations Economic Commission for Europe is implementing new web services. Keep an eye on progress here: http://www.unemed.org/edocs/index.htm



[ Top ]


Method Detail

Services_ExchangeRates (Constructor)   [line 162]

Services_ExchangeRates Services_ExchangeRates( [string $ratesSource = 'ECB'], [string $currencySource = 'UN'], [string $countrySource = 'UN'], [array $options = array(NULL)])

Constructor

This method overrides any default settings based on the $options parameter and retrieves feed data from the cache or their sources.

$options is an associative array:

  1.  $options = array(
  2.      'roundToDecimal'        => number of decimal places to round to (int),
  3.      'roundAutomatically'    => whether to automatically round to
  4.                                 $roundToDecimal digits (bool),
  5.      'thousandsSeparator'    => character to separate every 1000 (string),
  6.      'decimalCharacter'      => character for decimal place (string),
  7.      'cacheDirectory'        => path (with trailing slashto store cache
  8.                                 files (string),
  9.      'cacheLengthRates'      => length of time to cache exchange rates
  10.                                 file (int),
  11.      'cacheLengthCurrencies' => length of time to cache currency
  12.                                 list (int),
  13.      'cacheLengthCountries'  => length of time to cache country list (int),
  14.      'pearErrorMode'         => pear error mode (int));


Parameters:

string   $ratesSource   —  Driver name (filename minus 'Rates_' and .php) for exchange rate feed
string   $currencySource   —  Driver name for currency code list
string   $countrySource   —  Driver name for country code list (not yet used for anything)
array   $options   —  Array to override default settings

[ Top ]

convert   [line 260]

mixed convert( string $from, string $to, double $amount, [boolean $format = true])

Convert currencies
  • Return: Currency converted to $to

Parameters:

string   $from   —  Currency code of original currency
string   $to   —  Currency code of target currency
double   $amount   —  Amount of original currency to convert
boolean   $format   —  Format the final currency (add commas, round, etc.)

[ Top ]

format   [line 289]

string format( double $amount, [mixed $roundTo = null], [mixed $decChar = null], [mixed $sep = null])

Formats the converted currency

This method adds $this->_thousandsSeparator between every group of thousands, and rounds to $this->_roundToDecimal decimal places. Use the $options parameter on the constructor to set these values.

  • Return: Formatted currency

Parameters:

double   $amount   —  Number to format
mixed   $roundTo   —  Number of decimal places to round to (null for default)
mixed   $decChar   —  Character to use for decimal point (null for default)
mixed   $sep   —  Character to use for thousands separator (null for default)

[ Top ]

getRates   [line 309]

array getRates( string $referenceCurrency)

Get all rates as compared to a reference currency

Returns an associative array with currency codes as keys and formated rates as values, as computed against a reference currency.


Parameters:

string   $referenceCurrency   —  Reference currency code

[ Top ]

getValidCurrencies   [line 228]

array getValidCurrencies( array $currencies, array $rates)

Get list of currencies with known exchange rates

Creates an array of currency codes and their names, based on overlapping elements in $rates and $currencies.

  • Return: Array of currency codes to currency names that have a known exchange rate (sorted alphabetically)

Parameters:

array   $currencies   —  Array of currency codes to currency names
array   $rates   —  Array of currency codes to exchange rates

[ Top ]

isValidCurrency   [line 242]

void isValidCurrency( $code)


Parameters:

   $code   — 

[ Top ]

raiseError   [line 339]

void raiseError( string $msg, int $code)

Trigger a PEAR error

To improve performances, the PEAR.php file is included dynamically. The file is so included only when an error is triggered. So, in most cases, the file isn't included and performance is much better.


Parameters:

string   $msg   —  error message
int   $code   —  error code

[ Top ]

retrieveData   [line 207]

array retrieveData( string $source, int $cacheLength)

Factory

Includes the necessary driver, instantiates the class, retrieves the feed, and returns an associative array.

  • Return: Associative array containing the data requested

Parameters:

string   $source   —  Driver filename (minus .php; this includes 'Rates_', etc.)
int   $cacheLength   —  Cache length

[ Top ]

setToDebug   [line 324]

void setToDebug( )

Set to debug mode

When an error is found, the script will stop and the message will be displayed (in debug mode only).


[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:04:17 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.