PHPackages                             breeze\_converter/currency - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. breeze\_converter/currency

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

breeze\_converter/currency
==========================

This PHP Currency Conversion Library allows you to easily convert between different currencies using real-time exchange rates from a specified API.

v1.0.1(1y ago)16MITPHPPHP &gt;=7.4

Since Oct 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/israel-007/currency_convert_breeze)[ Packagist](https://packagist.org/packages/breeze_converter/currency)[ RSS](/packages/breeze-converter-currency/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Currency Converter Breeze
=========================

[](#currency-converter-breeze)

This currency conversion library is a simple, chainable PHP library that provides easy access to real-time currency conversion using exchange rates fetched from an external API `(https://api.exchangerate-api.com)`. It allows you to set a base currency, specify target currencies, and convert amounts with just a few lines of code. This library handles caching exchange rates in the session for efficiency and provides both array and JSON output formats for flexibility.

Key Features:
-------------

[](#key-features)

- Chainable methods: Set the base currency, target currencies, and amount in a fluid, intuitive way.
- Supports multiple currency conversions in a single call.
- Flexible output: Get results as an array or JSON.
- Error handling: Provides informative error messages and status responses.
- Session-based caching to minimize API requests.

Installation
------------

[](#installation)

You can install the library via Composer. Run the following command in your terminal:

```
composer require breeze_converter/currency
```

Make sure Composer is installed on your system. For more information on Composer, visit the [Composer Documentation](https://getcomposer.org/).

Getting Started
---------------

[](#getting-started)

Follow the steps below to start using the Converter library in your PHP project:

### 1. Basic Usage Example

[](#1-basic-usage-example)

Here's a quick example to convert an amount from one currency to multiple target currencies:

```
require 'vendor/autoload.php';

use converter\Converter;

try {
    $converter = new Converter([
        'basecurrency' => 'USD',  // Optional: default is 'USD'
        'defaultamount' => 100,   // Optional: default is 1
        'cookieexpiry' => 300     // Optional: caching duration in seconds
    ]);

    $result = $converter
        ->from('USD')                   // Set base currency
        ->to(['EUR', 'GBP', 'CAD'])     // Set target currencies
        ->amount(100)                   // Set amount to convert
        ->run('json');                  // Get result in JSON format

    echo $result;  // Output converted values as JSON

} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
```

### 2. Session Handling

[](#2-session-handling)

Ensure that PHP sessions are enabled as the library uses session-based caching for exchange rates.

Responses
---------

[](#responses)

The Converter library returns data in two formats: Array or JSON, depending on the output type you specify when calling the run() method.

### Successful Response

[](#successful-response)

If the conversion is successful, you'll receive a response with the status "success" and the converted values.

> Example (Array Format):

```
$response = $converter
    ->from('USD')
    ->to(['EUR', 'GBP'])
    ->amount(100)
    ->run('array');

print_r($response);
```

> Response:

```
$Array
(
    [status] => success
    [values] => Array
        (
            [EUR] => 93.5
            [GBP] => 83.2
        )
)
```

> Example (JSON Format):

```
$response = $converter
    ->from('USD')
    ->to(['EUR', 'GBP'])
    ->amount(100)
    ->run('json');

echo $response;
```

> Response

```
{
    "status": "success",
    "values": {
        "EUR": 93.5,
        "GBP": 83.2
    }
}
```

### Error Response

[](#error-response)

If an error occurs (e.g., invalid currency code, API failure), the library will return a response with the status `"error"` and an error message.

> Example:

```
$response = $converter
    ->from('USD')
    ->to(['INVALID'])
    ->run('array');

print_r($response);
```

> Response:

```
Array
(
    [status] => error
    [message] => "Currency conversion rate for INVALID not available."
)
```

Note

With just a few lines of code, you can convert amounts between multiple currencies, making this library ideal for e-commerce platforms, financial applications, and any service that requires currency conversion!

Default Settings
----------------

[](#default-settings)

The library provides a set of default values that can be used for ease of setup, while also allowing flexibility to override these settings using chainable methods.

1. Base Currency

- Default: `'USD'`
- By default, the library uses the US Dollar (`USD`) as the base currency for conversion. This means that unless specified otherwise, all conversions will be calculated from USD.
- How to Overwrite: Use the `baseCurrency()` method to specify a different base currency. For example, if you want to use Canadian Dollars (`CAD`) as the base currency:

```
$converter->baseCurrency('CAD');  // Sets the base currency to CAD
```

2. Default Amount

- Default: `1`
- If no specific amount is provided, the library defaults to converting `1` unit of the base currency to the target currencies. This is useful for quick rate checks.
- How to Overwrite: You can set a custom amount using the `defaultAmount()` method. For instance, to convert 100 CAD:

```
$converter->defaultAmount(100);  // Sets the amount to 100 units of the default currency
```

3. Cookie Expiry (Session Cache)

- Default: `300` seconds (5 minutes)
- The library caches exchange rates in the session for 5 minutes by default. This reduces the number of API requests, improving efficiency. Cached rates will be used within the specified expiry time, after which a new API request will be made.
- How to Overwrite: You can customize the caching time using the `expiry()` method. For example, to keep the cached rates for 5 minutes:

```
$converter->expiry(300);  // Set cache expiry time to 300 seconds (5 minutes)
```

- Impact of Reducing the Cookie Expiry Time: Reducing the expiry time means that the cached exchange rates will expire faster, leading to more frequent API calls. This can be useful if you need more up-to-date rates but can also lead to slower performance and hitting API rate limits. Conversely, increasing the expiry time (e.g., to 30 minutes) will reduce the number of API calls but may result in using outdated rates during that period.

> Example Usage with Custom Default Settings:

```
$converter = new Converter();

// Set base currency to CAD, default amount to 100, and cache expiry to 5 minutes
$converter->baseCurrency('CAD')
          ->defaultAmount(100)
          ->expiry(300);

// Convert from CAD to NGN, GBP, and USD, and get the result in JSON format
$result = $converter->to(['NGN', 'GBP', 'USD'])->run('json');

echo $result;
```

In this example:

- The base currency is set to `CAD` instead of the default `USD`.
- The amount to convert is set to `100` instead of the default `1`.
- The session cache expiry is set to `300` seconds (5 minutes).

Contributing
------------

[](#contributing)

Contributions are welcomed to this library Whether you're fixing bugs, adding new features, improving documentation, or suggesting enhancements, your contributions are valuable.

Feel free to submit pull requests or open issues if you encounter any problems or have suggestions for improvement.

Dependencies
------------

[](#dependencies)

This project does not rely on any external dependencies, making it easy to set up and use.

License
-------

[](#license)

This project is licensed under the [MIT License](LICENSE).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

575d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b6089fd8d3ecba23738d9118e9232d28e678b02e7ef4415ac9ea6010e452862?d=identicon)[israel-007](/maintainers/israel-007)

---

Top Contributors

[![israel-007](https://avatars.githubusercontent.com/u/76886811?v=4)](https://github.com/israel-007 "israel-007 (6 commits)")

### Embed Badge

![Health badge](/badges/breeze-converter-currency/health.svg)

```
[![Health](https://phpackages.com/badges/breeze-converter-currency/health.svg)](https://phpackages.com/packages/breeze-converter-currency)
```

###  Alternatives

[butschster/meta-tags

The most powerful and extendable tools for managing SEO Meta Tags in your Laravel project

628730.7k2](/packages/butschster-meta-tags)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
