pupitooo/bank

v1.0.1 2014-03-27 10:12 UTC

README

Bank is PHP script works with currencies. This extension is for Nette framework 2+.

Requirements

Pupitooo\Bank requires PHP 5.3.2 or higher.

Installation

The best way to install Pupitooo/Bank is using Composer:

$ composer require pupitooo/bank:@dev

Example NEON config

services:
    - Pto\Bank\Storages\Storage
    - Nette\Http\SessionSection(@session, 'bank')
    bank:
            class: Pto\Bank\Bank
            setup: 
                    - loadCurrency('EUR', NULL, {mask: '1 S', thousand: ' ', point: ',', zeroClear: FALSE, decimal: 2, symbol: € })
                    - loadCurrency('CZK', NULL, {mask: '1 S', thousand: ' ', point: ',', zeroClear: FALSE, decimal: 2, symbol: Kč})
                    - loadCurrency('USD')

Example Nette 2.1 use

In Presenter

    /** @var \Pto\Bank\Bank @inject */
    public $bank;

    protected function startup()
    {
        parent::startup();

        $bank = $this->bank;

        $bank->setDownload(\Pto\Bank\Bank::DOWNLOAD_METHOD_CNB);

        $bank->loadCurrency("CZK")
                ->setRate(27.8);
        $bank->loadCurrency("USD", NULL)
                ->setProfil(array('mask' => 'S 1', 'thousand' => ',', 'point' => '.', 'zeroClear' => FALSE, 'decimal' => 2, 'symbol' => '$'));
        $bank->loadCurrency("GBP", NULL, array('mask' => 'S 1', 'thousand' => ',', 'point' => '.', 'zeroClear' => FALSE, 'decimal' => 2, 'symbol' => '£'));
    }

    public function actionDefault()
    {
        $bank = $this->bank;

        Nette\Diagnostics\Debugger::barDump($bank->change(1, "EUR", "CZK"));
        Nette\Diagnostics\Debugger::barDump($bank->change(1, "EUR", "GBP"));
        Nette\Diagnostics\Debugger::barDump($bank->change(1, "EUR", "HUF"));

        Nette\Diagnostics\Debugger::barDump($bank->format(1, "EUR"));
        Nette\Diagnostics\Debugger::barDump($bank->format(1, "EUR", "CZK"));
        Nette\Diagnostics\Debugger::barDump($bank->format(1, "EUR", "USD"));
        Nette\Diagnostics\Debugger::barDump($bank->format(1, "EUR", "GBP"));
        
        \Nette\Diagnostics\Debugger::barDump($bank->getDefault());
        \Nette\Diagnostics\Debugger::barDump($bank->getActualRate("EUR"));
        \Nette\Diagnostics\Debugger::barDump($bank->getActualRate("CZK"));
        \Nette\Diagnostics\Debugger::barDump($bank->getActualRate("GBP"));
        \Nette\Diagnostics\Debugger::barDump($bank->getActualRate("USD"));
        \Nette\Diagnostics\Debugger::barDump($bank->getActualRate("HUF"));
    }

In Latte

    {1|currency} = {1|currencyTo:"EUR"}
    {1|currency} = {1|currencyTo:"CZK"}
    {1|currency} = {1|currencyTo:"USD"}
    {1|currency} = {1|currencyTo:"GBP"}

    {1|currency:"CZK"} = {1|currency:"CZK":"EUR"}
    {1|currency:"USD"} = {1|currency:"USD":"EUR"}
    {1|currency:"GBP"} = {1|currency:"GBP":"USD"}

Repository http://github.com/pupitooo/bank.