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

Class: Services_ExchangeRates

Source Location: /Services_ExchangeRates-0.8.0/Services/ExchangeRates.php

Class Overview


Exchange Rate package


Author(s):

Copyright:

  • Copyright 2003 Marshall Roch

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 67]
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 ]


Class Variables

$currencies =

[line 103]


Type:   mixed


[ Top ]

$options = array(
   /**
    * Sets the number of places to round the currencies to at the end
    * @access private
    * @var int
    */
    'roundToDecimal' => 2,

   /**
    * Determines whether the returned conversion is rounded or not
    * @access private
    * @var bool
    */
    'roundAutomatically' => true,

   /**
    * Defines single character used to separate each group of thousands in returned conversion
    * @access private
    * @var string
    */
    'thousandsSeparator' => ",",

   /**
    * Defines single character to use as a decimal place in returned conversion
    * @access private
    * @var string
    */
    'decimalCharacter' => "."
   )

[line 69]


Type:   mixed


[ Top ]

$rates =

[line 99]


Type:   mixed


[ Top ]

$ratesSource =

[line 100]


Type:   mixed


[ Top ]

$ratesUpdated =

[line 101]


Type:   mixed


[ Top ]

$validCurrencies =

[line 102]


Type:   mixed


[ Top ]



Method Detail

Services_ExchangeRates (Constructor)   [line 123]

Services_ExchangeRates Services_ExchangeRates( [array $options = array()])

Constructor

This method overrides any default settings based on the $options parameter and retrieves feed data from 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));


Parameters:

array   $options     Array to override default settings

[ Top ]

convert   [line 288]

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 ]

factory   [line 207]

Services_ExchangeRates_Common factory( string $source)

Instantiate a Rates or Currencies class

Parameters:

string   $source     Driver name - ie, Currencies_UN or Rates_NBI

[ Top ]

fetch   [line 187]

void fetch( Services_ExchangeRates_Rates $rates, Services_ExchangeRates_Rates $currencies)

Load all data from given drivers.

  1.  $rates = new Services_ExchangeRates();
  2.  
  3.  $rateProvider     $rates->factory('Rates_ECB');
  4.  $currencyProvider $rates->factory('Currencies_UN');
  5.  
  6.  $rates->fetch($rateProvider$currencyProvider);
  7.  
  8.  var_dump($rates->rates["AFA"])// 1.234
  9.  var_dump($rates->ratesUpdated)// 2008-12-24
  10.  var_dump($rates->currencies);
  11.  var_dump($rates->rates);


Parameters:

Services_ExchangeRates_Rates   $rates     A data provider of rates information
Services_ExchangeRates_Rates   $currencies     A data provider of currencies information

[ Top ]

format   [line 320]

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 343]

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 247]

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 269]

bool isValidCurrency( string $code)

Check if this is a valid currency

Parameters:

string   $code     Currency Code

[ Top ]

retrieveData   [line 230]

array retrieveData( string $source)

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.)

[ Top ]

setTransport   [line 158]

void setTransport( Services_ExchangeRates_Transport $transport)

Set the default transport to be used in Services_ExchangeRates_Common and other classes instantiated with factory()

Parameters:

Services_ExchangeRates_Transport   $transport     A class which implements a fetch() method

[ Top ]


Documentation generated on Tue, 23 Oct 2012 22:30:04 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.