Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php-cs-fixer.dist.php export-ignore
psalm.xml export-ignore
psalm-baseline.xml export-ignore
phpunit.xml.dist export-ignore
12 changes: 11 additions & 1 deletion .github/workflows/bc-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ name: Backward Compatibility Check
on:
pull_request:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
bc-check:
name: Backward Compatibility Check
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v6
Expand All @@ -20,7 +28,9 @@ jobs:
coverage: none

- name: Install dependencies
run: composer update --no-interaction --prefer-dist
uses: ramsey/composer-install@v3
with:
dependency-versions: highest

- name: Run BC Check
env:
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Coding Standards

on:
push:
branches: [master]
pull_request:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
php-cs-fixer:
name: PHP CS Fixer
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
uses: ramsey/composer-install@v3
with:
dependency-versions: highest

- name: Run PHP CS Fixer
run: composer cs:check

- name: How to fix
if: failure()
run: echo "::error::Coding style check failed. Run 'composer cs:fix' locally and commit the result."

facade-docblocks:
name: Facade docblocks
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
uses: ramsey/composer-install@v3
with:
dependency-versions: highest

- name: Lint facade docblocks
run: composer facade:lint

- name: How to fix
if: failure()
run: echo "::error::The Swap facade docblock is out of date. Run 'composer facade:fix' locally and commit the result."
16 changes: 14 additions & 2 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ on:
branches: [master]
pull_request:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
psalm:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v6
Expand All @@ -19,7 +27,11 @@ jobs:
coverage: none

- name: Install dependencies
run: composer update --no-interaction --prefer-dist
uses: ramsey/composer-install@v3
with:
dependency-versions: highest

# On pushes to master, also send type coverage to shepherd.dev (README badge).
# Pull request runs don't, so the coverage history only follows master.
- name: Run Psalm
run: vendor/bin/psalm --no-progress
run: vendor/bin/psalm --no-progress --output-format=github ${{ github.event_name == 'push' && '--shepherd' || '' }}
27 changes: 0 additions & 27 deletions .github/workflows/style.yml

This file was deleted.

22 changes: 20 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,29 @@ on:
branches: [master]
pull_request:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
tests:
runs-on: ubuntu-latest
timeout-minutes: 15

strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4', '8.5']
laravel: ['12', '13']
exclude:
# Laravel 13 requires PHP 8.3.
- php: '8.2'
laravel: '13'

name: PHP ${{ matrix.php }}
name: PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }}

steps:
- uses: actions/checkout@v6
Expand All @@ -25,8 +38,13 @@ jobs:
php-version: ${{ matrix.php }}
coverage: none

- name: Pin Laravel ${{ matrix.laravel }}
run: composer require "illuminate/contracts:^${{ matrix.laravel }}.0" "illuminate/support:^${{ matrix.laravel }}.0" --no-update --no-interaction

- name: Install dependencies
run: composer update --no-interaction --prefer-dist
uses: ramsey/composer-install@v3
with:
dependency-versions: highest

- name: Run tests
run: vendor/bin/phpunit
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/vendor/
composer.lock
phpunit.xml
.php_cs.cache
.php-cs-fixer.cache
.phpunit.cache
.phpunit.result.cache
17 changes: 17 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

return (new Config())
->setRiskyAllowed(false)
->setRules([
'@PER-CS3x0' => true,
'@PHP82Migration' => true, // target PHP 8.2 syntax
])
->setFinder(
(new Finder())
->in(__DIR__)
);
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

[![Tests](https://github.com/florianv/laravel-swap/actions/workflows/tests.yml/badge.svg)](https://github.com/florianv/laravel-swap/actions/workflows/tests.yml)
[![Psalm](https://github.com/florianv/laravel-swap/actions/workflows/psalm.yml/badge.svg)](https://github.com/florianv/laravel-swap/actions/workflows/psalm.yml)
[![Type coverage](https://shepherd.dev/github/florianv/laravel-swap/coverage.svg)](https://shepherd.dev/github/florianv/laravel-swap)
[![Total Downloads](https://img.shields.io/packagist/dt/florianv/laravel-swap.svg?style=flat-square)](https://packagist.org/packages/florianv/laravel-swap)
[![Version](http://img.shields.io/packagist/v/florianv/laravel-swap.svg?style=flat-square)](https://packagist.org/packages/florianv/laravel-swap)

> _Drop-in currency conversion for Laravel and Lumen. Auto-discovered service provider, facade, and config. Maintained since 2014._
> _Drop-in currency conversion for Laravel. Auto-discovered service provider, facade, and config. Maintained since 2014._

<table>
<tr>
Expand All @@ -23,25 +24,24 @@

**Install, publish the config, and call `Swap::latest('EUR/USD')` from anywhere. No service container wiring, no boilerplate, no manual cache plumbing.**

Laravel Swap is a drop-in package for **Laravel currency conversion**. The service provider is auto-discovered in Laravel 5.5+; configuration publishes to `config/swap.php`; rates are cached through the Laravel cache store you already have. Lumen is supported.
Laravel Swap is a drop-in package for **Laravel currency conversion**. The service provider is auto-discovered; configuration publishes to `config/swap.php`; rates are cached through the Laravel cache store you already have.

## 💡 What is Laravel Swap?

- The Laravel application of [Swap](https://github.com/florianv/swap), the PHP currency conversion library.
- A service provider (`Swap\Laravel\SwapServiceProvider`) and a `Swap` facade, auto-discovered in Laravel 5.5+.
- A service provider (`Swap\Laravel\SwapServiceProvider`) and a `Swap` facade, both auto-discovered.
- Configuration published to `config/swap.php`.
- Rates cached through any Laravel cache store you already have.
- Lumen support with a few extra lines in `bootstrap/app.php`.

## 📦 Installation

Laravel Swap requires PHP 8.2 or newer.
Laravel Swap requires PHP 8.2 or newer and Laravel 12 or 13.

```bash
composer require florianv/laravel-swap symfony/http-client nyholm/psr7
```

Auto-discovery wires the service provider and the `Swap` facade in Laravel 5.5+. For Lumen or older Laravel versions, see [Setup](doc/readme.md#-setup) in the documentation.
Auto-discovery wires the service provider and the `Swap` facade. To register them manually, see [Setup](doc/readme.md#-setup) in the documentation.

## ⚡ Quickstart

Expand Down Expand Up @@ -140,6 +140,7 @@ Laravel Swap supports the 30+ exchange rate providers from the underlying [Swap]
| Central Bank of the Republic of Turkey | `central_bank_of_republic_turkey` | * | TRY | Yes |
| Central Bank of the Republic of Uzbekistan | `central_bank_of_republic_uzbekistan` | * | UZS | Yes |
| European Central Bank | `european_central_bank` | EUR | * | Yes |
| National Bank of Denmark | `national_bank_of_denmark` | (limited list) | (limited list) | Yes |
| National Bank of Georgia | `national_bank_of_georgia` | * | GEL | Yes |
| National Bank of Romania | `national_bank_of_romania` | (limited list) | (limited list) | Yes |
| National Bank of the Republic of Belarus | `national_bank_of_republic_belarus` | * | BYN | Yes |
Expand All @@ -150,13 +151,13 @@ The per-provider option names (`api_key` vs `access_key` vs `app_id`, optional f

## 🎯 When should you use Laravel Swap?

- Use Laravel Swap when you need exchange rates inside a Laravel or Lumen application: localized prices, invoice totals, multi-currency reporting, historical FX data.
- Use Laravel Swap when you need exchange rates inside a Laravel application: localized prices, invoice totals, multi-currency reporting, historical FX data.
- You do not need to install [Swap](https://github.com/florianv/swap) separately. It is pulled in as a dependency, and Laravel Swap exposes it through Laravel's service container, facade, and cache store.

## 🛠 Common use cases

- Display localized prices in multi-currency Laravel storefronts.
- Compute invoice totals across currencies in a Laravel or Lumen API.
- Compute invoice totals across currencies in a Laravel API.
- Reconcile multi-currency ledgers using historical rates.
- Power internal FX dashboards with rate history.
- Build currency conversion infrastructure for Laravel-based fintech and ERP applications.
Expand All @@ -174,7 +175,7 @@ All four packages are MIT-licensed and require PHP 8.2 or newer.

## 📚 Documentation

The full documentation, with Lumen setup, per-provider configuration, custom service registration, and FAQ, is in [`doc/readme.md`](doc/readme.md).
The full documentation, with per-provider configuration, custom service registration, and FAQ, is in [`doc/readme.md`](doc/readme.md).

## 🙌 Contributing

Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"keywords": [
"php",
"laravel",
"lumen",
"currency-conversion",
"exchange-rates",
"exchange-rate-api",
Expand Down Expand Up @@ -33,7 +32,9 @@
},
"require": {
"php": "^8.2",
"florianv/swap": "^4.0"
"florianv/swap": "^4.6",
"illuminate/contracts": "^12.0 || ^13.0",
"illuminate/support": "^12.0 || ^13.0"
},
"require-dev": {
"graham-campbell/testbench": "^6.2",
Expand All @@ -42,7 +43,9 @@
"psalm/plugin-laravel": "^4.13",
"roave/backward-compatibility-check": "^8.9",
"php-http/guzzle7-adapter": "^1.0",
"nyholm/psr7": "^1.0"
"nyholm/psr7": "^1.0",
"friendsofphp/php-cs-fixer": "^3.95",
"psalm/plugin-phpunit": "^0.20.4"
},
"repositories": [
{
Expand All @@ -53,8 +56,8 @@
],
"scripts": {
"test": "vendor/bin/phpunit",
"facade:fix": "php -f vendor/bin/facade.php Swap\\Laravel\\Facades\\Swap --write",
"facade:lint": "php -f vendor/bin/facade.php Swap\\Laravel\\Facades\\Swap",
"facade:fix": "php -f vendor/bin/facade.php -- 'Swap\\Laravel\\Facades\\Swap'",
"facade:lint": "php -f vendor/bin/facade.php -- --lint 'Swap\\Laravel\\Facades\\Swap'",
"psalm": "vendor/bin/psalm --no-progress",
"cs:fix": "vendor/bin/php-cs-fixer fix --no-interaction --ansi --quiet",
"cs:check": "vendor/bin/php-cs-fixer fix --no-interaction --ansi --verbose --dry-run"
Expand All @@ -66,7 +69,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
"dev-master": "2.x-dev"
},
"laravel": {
"providers": [
Expand Down
Loading
Loading