Download the PHP package hennest/exchange-rate without Composer
On this page you can find all versions of the php package hennest/exchange-rate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hennest/exchange-rate
More information about hennest/exchange-rate
Files in hennest/exchange-rate
Package exchange-rate
Short Description Exchange rate provider for laravel apps
License MIT
Informations about the package exchange-rate
Exchange Rate Library
This PHP library provides a flexible and efficient way to handle exchange rates, including fetching current rates, caching, and currency conversion. It's designed to integrate seamlessly with Laravel applications.
Features
- Fetch exchange rates from multiple API sources
- Cache exchange rates for improved performance
- Parse and filter exchange rate data
- Perform currency conversions with configurable precision
- Easily extensible and customizable
- Laravel integration via a service provider
Installation
You can install this library via Composer:
Laravel Integration
This library comes with a Laravel service provider for easy integration. After installation, add the service provider to your config/app.php
file:
Configuration
Publish the configuration file:
This will create a config/exchange-rate.php
file where you can customize the library settings.
Usage
Basic Usage
Configuration Options
The config/exchange-rate.php
file allows you to customize various aspects of the library. Here's a breakdown of the available options:
Key Configuration Options:
base_currency
: Set your preferred base currency (default: USD).api_key
: If your chosen API requires a key, set it here or in your.env
file.math.scale
: Set the precision for decimal calculations.cache
: Configure caching options including driver, prefix, and TTL.services
: Override default service implementations.default_driver
: Choose the default API driver.drivers
: Configure multiple API drivers for flexibility.
Extending the Library
You can set default_driver
to null
and update the services
array to extend the library's functionality. You can create custom implementations of the following interfaces:
ApiInterface
: For custom API integrationsCacheInterface
: For custom caching mechanismsParserInterface
: For custom parsing logicExchangeRateInterface
: For custom exchange rate calculations
Register your custom implementations in the services
section of the config/exchange-rate.php
file:
This allows you to have full control over which services are used throughout your application.
Multiple API Drivers
The library supports multiple API drivers. You can add new drivers in the drivers
section and switch between them by changing the default_driver
setting.
Adding Custom Drivers
To add a custom driver or use a different API service, extend the library by adding a new entry to the drivers
array in the config/exchange-rate.php
file:
Selecting a Driver
To use your custom driver, you can either:
-
Update the
default_driver
setting in the config file: - Or set it using an environment variable:
Custom Implementations
When creating custom implementations, ensure they adhere to the following interfaces:
ApiInterface
: For custom API integrationsCacheInterface
: For custom caching mechanismsParserInterface
: For custom parsing logicExchangeRateInterface
: For custom exchange rate calculations
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This library is open-sourced software licensed under the MIT license.