2017 © Pedro Peláez
 

library cuex

Currency Exchange rates library for PHP

image

tautiz/cuex

Currency Exchange rates library for PHP

  • Sunday, November 29, 2015
  • by tautiz
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

CuEx

Currency Exchange rates library for PHP, (*1)

Installation

$ composer require tautiz/CuEx

Add service to App providers array:, (*2)

CuEx\CuExServiceProvider::class,

Usage

Create an HTTP adapter, (*3)

$httpAdapter = new \Ivory\HttpAdapter\FileGetContentsHttpAdapter();

Then, you can create a provider and add it to CuEx:, (*4)

// Create the Yahoo Finance provider
$provider = new \CuEx\Provider\YahooFinanceProvider($httpAdapter);

// Create CuEx with the provider
$cuex = new \CuEx\CuEx($provider);

Quoting

To retrieve the latest exchange rate for a currency pair, you need to use the quote() method., (*5)

$rate = $cuex->getRate('EUR/LTL');

// 3.4528
echo $rate;

// 3.4528
echo $rate->getValue();

// 15-11-28 23:59:59
echo $rate->getDate()->format('Y-m-d H:i:s');

Currencies are expressed as their ISO 4217 code., (*6)

Chaining providers

It is possible to chain providers in order to use fallbacks in case the main providers don't support the currency or are unavailable. Simply create a ChainProvider wrapping the providers you want to chain., (*7)

$chainProvider = new \CuEx\Provider\ChainProvider([
    new \CuEx\Provider\YahooFinanceProvider($httpAdapter),
    new \CuEx\Provider\CurrencylayerProvider($httpAdapter,'<YOUR_ACCESS_KEY>'),
    new \CuEx\Provider\FixerProvider($httpAdapter),
    new \CuEx\Provider\GoogleFinanceProvider($httpAdapter),
]);

The rates will be first fetched using the Yahoo Finance provider and will fallback to Google Finance., (*8)

Caching

For performance reasons you might want to cache the rates during a given time., (*9)

Doctrine Cache

Installation
$ composer require doctrine/cache
Usage
// Create the cache adapter
$cache = new \CuEx\Cache\DoctrineCache(new \Doctrine\Common\Cache\ApcCache(), 3600);

// Pass the cache to CuEx
$cuex = new \CuEx\CuEx($provider, $cache);

All rates will now be cached to 3600 minutes., (*10)

Currency Codes

CuEx provides an enumeration of currency codes so you can use autocompletion to avoid typos., (*11)

use \CuEx\Util\CurrencyCodes;

// Retrieving the EUR/LTL rate
$rate = $cuex->quote(new \CuEx\Model\CurrencyPair(
    CurrencyCodes::ISO_EUR,
    CurrencyCodes::ISO_LTL
));

License

MIT, (*12)

The Versions

29/11 2015

dev-master

9999999-dev https://github.com/tautiz/cuex

Currency Exchange rates library for PHP

  Sources   Download

MIT

The Requires

 

by Tautvydas Dulskis