h4kuna/exchange

Exchange between currencies.

Installs: 479

Dependents: 0

Stars: 10

Watchers: 3

Forks: 4

Open Issues: 1

Language: PHP

v4.1.0 2015-06-12 07:41 UTC

README

Build Status

Exchange is PHP script works with currencies. This extension is primary for Nette framework 2+, but you can use without Nette for another framework or without framework.

Installation to project

The best way to install h4kuna/exchange is using Composer:

$ composer require h4kuna/exchange

Example NEON config

extensions:
    exchangeExtension: h4kuna\Exchange\Nette\DI\ExchangeExtension

exchangeExtension:
    currencies: {
            czk: [decimal: 0, symbol: 'Kč', point: ',', thousand: ' ', mask: '1 S', flag: 10]
            usd: [symbol: '$']
            gbp: [mask: 'S1', thousand: '.', symbol: '£', decimal: 2] }
    vat: 21
    vatIn: false
    vatOut: false

Basic usage.

/* @var $exchange h4kuna\Exchange\Exchange */
$exchange->setDate(new DateTime('2000-12-30'));
$exchange->format(10, 'eur', 'czk'); // 351 Kč

Method format has parameters: - money (int/float) - from, this can be global set by method setDefault() - to, this can be global set by method setWeb() - vat, this can be global set by method setVat()

If you want all currencies. Default is load whose are in config.

$exchange->loadAll(); // array of h4kuna\Exchange\Currency\IProperty

Change default currency. Normaly default is first in config.

$exchange->setDefault('czk');
$this->exchange->format(10); // 10 Kč
$exchange->setDefault('gbp');
$exchange->format(10); // 564 Kč, there is czk output
$exchange->format(10, NULL, 'gbp'); // £10.00
// or
$exchange->setWeb('gbp');
$exchange->format(10); // £10.00

Change driver on fly.

$exchange->setDate(); // reset history to current
$ecbDriver = $exchange->setDriver(new Driver\Ecb\Day); // Ecb does not support history, yet
$ecbDriverExchange->format(10);