Download the PHP package jdrda/cnb-currency-converter without Composer

On this page you can find all versions of the php package jdrda/cnb-currency-converter. 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 cnb-currency-converter

CNB Currency Converter 💱🇨🇿

Symfony Cache PSR-6 Composer CNB Packagist Version Packagist Downloads

A small PHP currency converter using the official daily exchange-rate table published by the Czech National Bank (CNB).

It can:

Installation

Requirements

The package allows multiple Symfony Cache major versions, so Composer can choose a version that fits the PHP runtime:

Basic usage

Historical rates

Pass a date to the constructor. The package accepts a parseable date string or a DateTimeInterface object.

Dates before 1991 are rejected. Future dates are rejected as well.

Converting through CZK

The CNB table is a CZK-based table. It does not publish direct EUR/USD, GBP/JPY or CHF/PLN cross rates. This package therefore calculates every conversion like this:

Example:

Internally this is equivalent to:

This matters because some CNB rows are not quoted for one unit:

For JPY, the normalized rate is therefore:

Rounding

By default, convert() returns a raw floating-point result.

Pass the fourth argument to round the result:

CZK support

CZK is supported as a built-in synthetic currency even though it is not listed as a normal row in the CNB table.

Cache

Downloaded CNB text files are cached for one day by default.

The default constructor uses Symfony's FilesystemAdapter:

You can inject any PSR-6 cache pool. This is usually the best option inside Symfony, Laravel or another framework, because your application can own the cache configuration.

You can also change the cache TTL:

Laravel example

Laravel does not expose a PSR-6 cache pool directly through its normal cache facade. The simplest option is to let this package use its default Symfony FilesystemAdapter, or register your own PSR-6 adapter in the container.

Symfony example

Then inject it into your service or controller:

API

__construct($date = null, CacheItemPoolInterface $cache = null, $cacheTtl = null)

Creates a converter.

rate($currencyCode)

Returns an ExchangeRate object.

rates()

Returns all loaded rates indexed by currency code.

czkPerUnit($currencyCode)

Returns the normalized CZK value for one unit of the requested currency.

convert($amount, $fromCurrency, $toCurrency, $precision = null)

Converts through CZK.

getPublishedDate()

Returns the date published in the CNB file after the table has been loaded.

getSequenceNumber()

Returns the CNB sequence number from the first line of the source file.

Exceptions

The package throws exceptions from the CnbCurrencyConverter\Exception namespace:

All package exceptions extend CurrencyConverterException.

Data source

The package uses the official CNB daily exchange-rate TXT endpoint:

For historical rates it uses:

Development

Run syntax checks manually if needed:

License

MIT. See LICENSE.


All versions of cnb-currency-converter with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.3
psr/cache Version ^1.0 || ^2.0 || ^3.0
symfony/cache Version ^4.4 || ^5.4 || ^6.4 || ^7.0
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 jdrda/cnb-currency-converter contains the following files

Loading the files please wait ...