XRates extends ExchangeRate
X-Rates Currency Exchange Rate Processor
Table of Contents
Properties
| $key | |
| $timeout | |
| $url |
Methods
| __construct() | Initializes the exchange rate processor |
| getRate() | Fetches the exchange rate from currency A to currency B using the given amount |
| requiresKey() | Determines whether an API key is necessary to retrieve exchange rates via the processor |
| setKey() | Sets the API key necessary to retrieve exchange rates |
| convertRates() | Updates all currency rates given to convert the rates relative to the given currency |
| parseRate() | Parses HTML to determine the conversion rate |
Methods
__construct()
Initializes the exchange rate processor
public
__construct(Http $Http) : mixed
Parameters
- $Http : Http
-
The Http component to more easily facilitate HTTP requests to fetch data
getRate()
Fetches the exchange rate from currency A to currency B using the given amount
public
getRate(string $currency_from, string $currency_to[, float $amount = 1.0 ]) : mixed
Parameters
- $currency_from : string
-
The ISO 4217 currency code to convert from
- $currency_to : string
-
The ISO 4217 currency code to convert to
- $amount : float = 1.0
-
The amount to convert
Return values
mixed —(boolean) false on error or an array containing the exchange rate information including:
- rate The exchange rate for the supplied amount
- updated The date/time of the last update in YYYY-MM-DD HH:MM:SS format in UTC time
requiresKey()
Determines whether an API key is necessary to retrieve exchange rates via the processor
public
requiresKey() : bool
Return values
bool —True if an API key is required, or false otherwise
setKey()
Sets the API key necessary to retrieve exchange rates
public
setKey(string $key) : mixed
Parameters
- $key : string
-
The key for the exchange rate processor API
convertRates()
Updates all currency rates given to convert the rates relative to the given currency
protected
convertRates(string $to_currency, array<string|int, mixed> $rates) : array<string|int, mixed>
Parameters
- $to_currency : string
-
The ISO 4217 currency code to convert relative to
- $rates : array<string|int, mixed>
-
A key/value list of all currencies and their rates. The $to_currency must be in the list
Return values
array<string|int, mixed> —A key/value list of all currency exchange rates
parseRate()
Parses HTML to determine the conversion rate
private
parseRate(string $html) : mixed
Parameters
- $html : string
-
The HTML page containing the rate
Return values
mixed —The conversion rate, if available, otherwise boolean false