fortis / iso-currency
A PHP library providing ISO 4217 currencies. Work with currencies by the standard to avoid confusions.
Installs: 119 017
Dependents: 2
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 6
Open Issues: 2
Requires
- php: >=5.6
Requires (Dev)
- php-http/guzzle6-adapter: ^1.1
- php-http/httplug: ^1.1
- php-http/message: ^1.6
- phpunit/phpunit: 5.*
- satooshi/php-coveralls: 1.*
- twig/twig: ^1.34
This package is auto-updated.
Last update: 2024-11-13 22:47:40 UTC
README
Very simple and easy-to-use Currency
class to work with ISO 4217 currencies as they provided by the official ISO Maintenance Agency
What is ISO 4217
ISO 4217 is a standard published by the International Organization for Standardization, which delineates currency designators, country codes (alpha and numeric), and references to minor units in three tables.
-- Wikipedia
Install
Install directly from command line using Composer
composer require fortis/iso-currency
Use
Don't type currency codes as strings, instead it's better to use constants from auto generated CurrencyCode class as it's always up-to-date with currency-iso.org and helps you avoid typos.
For example, use CurrencyCode::USD
instead of 'USD'
. Autocomplete will make it easier.
Also you can create new currency object with Currency class and autocomplete: new Currency::USD()
.
// Create Currency instance. $currency = new Currency(CurrencyCode::EUR); // constructor $currency = Currency::create(CurrencyCode::EUR); // static factory method $currency = Currency::EUR(); // short syntax with autocomplete on :: // Currency code validation. $currency = new Currency('EUE'); // throws InvalidCurrencyException // Check whether the given Currency is USD/EUR/etc. $currency = new Currency(CurrencyCode::EUR); $currency->is(Currency::EUR()); // true $currency->is(Currency::USD()); // false
License
iso-currency is licensed under the MIT license.
Source(s)
- "ISO 4217" by Wikipedia licensed under CC BY-SA 3.0 Unported License