Download the PHP package stichoza/nbg-currency without Composer

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

NBG Currency

Latest Stable Version Total Downloads

National Bank of Georgia (NBG) currency service API wrapper in PHP

Installation

Install this package via Composer.

Note PHP 8.1 or later is required. Use following versions of this package for older PHP versions:

Package version PHP Version Documentation
v3.0 PHP >= 8.1 v3 Docs
v2.0 PHP >= 7.1.8 v2 Docs
v1.2 PHP >= 5.5.9 v1.2 Docs (Not working)

Quick Examples

Continue reading for more details about additional functionality.

Basic Usage

The class is namespaced as Stichoza\NbgCurrency\NbgCurrency:

This package has three main static methods from which you can access currency rates.

Get Currency Rate

The NbgCurrency::rate() method returns a currency rate in float.

Parameter Default Description
$code Currency code, not case-sensitive
$date null Date of currency rate: Carbon, DateTime, string or null.

Important The rate is always for a single unit. The original NBG JSON API returns rate for different amounts per currency. For example Japanese Yen (JPY) rate will be 1.9865 and quantity will be set to 100 (100 JPY is 1.9865 GEL). It is quite confusing during calculations so this package always returns price per single unit. So in this case JPY will be 0.019865 (1 JPY is 0.019865 GEL).

Examples:

When passing dates as Carbon or DateTime objects, it's recommended to have its timezone set to Asia/Tbilisi to avoid unexpected behavior. For convenience, timezone string is available as NbgCurrency::TIMEZONE class constant.

Get Currency Object

The NbgCurrency::get() method returns a Currency object containing data of a currency for specified date.

This method accepts same parameters as ::rate() method and one additional parameter for language (Used for currency name).

Parameter Default Description
$code Currency code, not case-sensitive
$date null Date of currency rate
$language ka Language for currency name (Currently only en or ka)

Examples:

Note All properties of Currency class are declared as readonly. Updating them will result in Fatal Error.

Advanced Usage

Get All Currencies

The NbgCurrency::date() method will return a Currencies object. This is a collection-like object that contains a list of all Currency objects available for specified date.

Parameter Default Description
$date null Date of currency rates
$language ka Language for names of currencies (Currently only en or ka)

Examples:

Currencies class has date attribute and several methods that you can use.

Note that ->get() method of Currencies object has only one parameter string $code, while the static method with the same name (NbgCurrency::get()) has two additional parameters described in basic usage examples above.

The Currencies object also implements Countable and IteratorAggregate interfaces, so you can use the object in foreach loops and count() function.

Examples:

Error Handling

There are 5 exceptions in Stichoza\NbgCurrency\Exceptions namespace that could be thrown from methods:

All exceptions above extend Exception class, so you can handle all exceptions by catching Exception or Throwable.

Additional Info

Number of HTTP Requests

When you access any currency, all currencies for that day in selected language will be fetched (API returns all currencies in a single request) and stored in NbgCurrency class attribute. When you request any other currency, no additional HTTP requests will be made for same date and language.

Memory Usage & Caching

By default, all retrieved currencies are stored in a static property of NbgCurrency class. If you're planning to get currencies for many different dates, it might use excessive memory. In this case it's recommended to turn off the caching feature.

On the other hand, disabling caching may increase number of HTTP requests being sent. Example:

The above code would make a single HTTP request to the API when caching is enabled. But if you disable caching, it will send 5 separate HTTP requests. To load multiple currencies of same date using a single HTTP request with caching disabled, you can use ::date() method to get Currencies object and then access all contained objects after.

In this case there will be a single HTTP request made even with caching disabled.

Keywords

ლარის კურსი, ეროვნული ბანკის გაცვლითი კურსი, ვალუტა, ლარის ვალუტის კურსი, laris kursi, laris valuta, lari currency, national bank of georgia, nbg


All versions of nbg-currency with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-json Version *
nesbot/carbon Version ^2.32.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 stichoza/nbg-currency contains the following files

Loading the files please wait ....