Download the PHP package runopencode/exchange-rate without Composer

On this page you can find all versions of the php package runopencode/exchange-rate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package exchange-rate

Exchange rate

Fetch, store and use currency exchange rates in your application

Packagist Scrutinizer Code Quality Code Coverage Build Status Build Status

SensioLabsInsight

About domain problem when working with exchange rates on your web shop/accounting application, or similar.

If you are building any kind of accounting application or some kind of web store that deals with various currency exchange rates, you are probably have to deal with exchange rates.

Exchange rate calculator is easy job, however, acquiring proper exchange rate to work with can be hassle, especially since all exchange rates are provided by external third party, accessible via some API. That means that your application depends on availability of third party API.

Now, considering that (at least in business theory) exchange rates are established every working day at 2PM by national banks for next day (Friday for Saturday and Sunday) and those rates are unchanged during working day (at least not on goods and service) market, you should be able to fetch rates in advance only once, and use them from your own local source, without fetching rates from external source for that day. Commercial banks follows similar practice, national bank will determine lower and upper buying/selling rates, and commercial banks can establish their prices within that range (after all, money trading is trading business in its basis).

In general, your job is to fetch rates with which your application works with in advance, store them on some local repository, and use those rates from that point from your local source.

This library solves that problem providing necessary classes and tools that will help you with dealing with exchange rates.

Note that this library is not exchange rate calculator.

Architecture of the system

System defines 6 core components:

Anatomy of Rate

Let's consider rate:

Manager

Manager follows rate anatomy, and exposes API which allows you to query for rate which you need:

System defines 'median' rate, considering that every Source will provide you with at least one rate type, which is usually a median. Every implementation should declare one of available rate types as default on. Recommendation is to consider 'median' rate type as default.

Bootstrapping manager

In example bellow you can find example of manager initialization, which you can use in your application.

    // We are using Composer for autoloading
    include 'vendor/autoload.php';

    use RunOpenCode\ExchangeRate\Configuration;
    use RunOpenCode\ExchangeRate\Manager;
    use RunOpenCode\ExchangeRate\Processor\BaseCurrencyValidator;
    use RunOpenCode\ExchangeRate\Processor\UniqueRatesValidator;
    use RunOpenCode\ExchangeRate\Registry\ProcessorsRegistry;
    use RunOpenCode\ExchangeRate\Registry\RatesConfigurationRegistry;
    use RunOpenCode\ExchangeRate\Registry\SourcesRegistry;
    use RunOpenCode\ExchangeRate\Repository\FileRepository;

    // Create sources registry
    $sourcesRegistry = new SourcesRegistry();

    // And register your sources. You can make your own sources, or find them on packagist, this is just example.
    $sourcesRegistry->add(new MySource());
    $sourcesRegistry->add(new MyOtherSource());

    // Create your configuration, register which rates you would like to fetch
    $configurationsRegistry = new RatesConfigurationRegistry(array(
        new Configuration('EUR', 'median', 'my_source'),
        new Configuration('CHF', 'median', 'my_source'),
        new Configuration('USD', 'median', 'my_other_source'),
    ));

    // Register your processors
    $processorsRegistry = new ProcessorsRegistry(array(
        new BaseCurrencyValidator(),
        new UniqueRatesValidator()
    ));

    // Provide repository
    $repository = new FileRepository('path/to/file/rates.db');

    // ... and initialize manager.
    $manager = new Manager('RSD', $repository, $sourcesRegistry, $processorsRegistry, $configurationsRegistry);

Crontab and fetching rates

As in example above, you can make a similar script that will be executed by crontab every day to fetch fresh rates.

    $manager = new Manager('RSD', $repository, $sourcesRegistry, $processorsRegistry, $configurationsRegistry);
    $manager->fetch();

Some design notes and guidelines

When you design a system that uses rates from this library, and even if you use DB as storage for rates persistence - DO NOT establish relation with rates. That is very bad practice! If you have, per example, an invoice in foreign currency, do copy all data from Rate to your invoice model, do not reference Rate via foreign key, or by any other method.

The reason for that is to have data consistency and flexibility:

  1. Your client can agree with buyer/seller specific exchange rate. This is quite possible and legit, if relation is used than this request can not be supported.
  2. If error is spotted in exchange rate value and if relation exists, it could not be corrected, because all issued and paid invoices referencing that rate would be affected. That would mean that those invoices would have to be stored and re-issued, and user of system would be forced to do additional explaining to his clients.

However - if there is a data redundancy, that is, you copy all values from Rate to your model, all possibilities for occurrence of issues stated above would be avoided.

Known implementations of sources

Below is the list of known implementations of exchange rates sources for this library which you can use in your projects:

Known bridges

Below is the list of known bridges for PHP frameworks:


All versions of exchange-rate with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
psr/log Version 1.*
roave/security-advisories Version dev-master
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package runopencode/exchange-rate contains the following files

Loading the files please wait ....