greksazoo / mnb-exchange-laravel
This is a MNB(Magyar Nemzeti Bank) exchange rate query package for Laravel.
Requires
- php: ^7.4|^8.0|^8.1|^8.2
- ext-simplexml: *
- ext-soap: *
- illuminate/cache: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0
- illuminate/support: ^8.0|^9.0|^10.0
Requires (Dev)
- mockery/mockery: ^1.5
- orchestra/testbench: ^v6.0|^v7.0
- phpstan/phpstan: ^1.9.17
- phpunit/phpunit: ^9.0|^10.0
README
This is a MNB Exchange Rate query package for Laravel v8 or above.
Requirements
Package requires PHP v7.4 or above, with Soap and SimpleXml. Not tested with previous versions of Laravel.
Know-how
This package is mainly based on top of MNB package and MNB Laravel package.
Installation
You can install the package via composer:
composer require greksazoo/mnb-exchange-laravel
Configuration
Export
php artisan vendor:publish --provider="Greksazoo\MnbExchangeLaravel\MnbExchangeLaravelServiceProvider" --tag="config"
config/mnb-exchange.php
/* * Wsdl file location. * */ 'wsdl' => env('MNB_SOAP_WSDL', 'http://www.mnb.hu/arfolyamok.asmx?wsdl'), 'cache' => [ /* * Desired cache driver for service. * */ 'store' => env('MNB_CACHE_DRIVER', 'file'), /* * Minutes the cached currencies will be held for. * Default: 24hrs (1440) * */ 'timeout' => env('MNB_CACHE_MINUTES', 1440), ]
Usage
Access via facade
use Greksazoo\MnbExchangeLaravel\Facade\Mnb $currency = Mnb::currentExchangeRate('EUR'); echo $currency->code; // 'EUR' echo $currency->getCode(); // 'EUR' echo $currency->unit; // '1' echo $currency->getUnit(); // '1' echo $currency->amount; // '350' echo $currency->getAmount(); // '350'
Resolve by application container
$currency = app(\Greksazoo\MnbExchangeLaravel\MnbExchangeLaravel::class)->currentExchangeRate('EUR');
Access refresh date by reference
You can check the feed date by passing a $date variable to some methods. These methods will make variable to be a Carbon instance.
Mnb::exchangeRates($date); $date->isToday();
Available methods
Won't use cache
These methods won't use and update cache.
- currentExchangeRate($code, &$date = null): Currency
- currentExchangeRates(&$date = null): array of Currency
Will use cache
These methods will use cache.
- exchangeRate($code, &$date = null): single Currency
- exchangeRates(&$date = null): array of currencies
- currencies(): array of strings (each is currency code)
- hasCurrency($code): bool
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email zoli.greksa@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.