Peso Framework
Another thing I've been secretly building is the Peso Framework, a tool to query currency conversion rates.
It started when I was pissed that florianv/exchanger
, a tool I was perfectly happy with previously, got a broken release (2.8.2) got abandoned for almost a year now, and still isn't fixed as of this post.
Peso consists of 3 components:
A service (data source)
An integration (data consumer)
A glue library (
peso/core
) that contains the Service contract, standard request/response objects, and useful tools to develop services and integrations
A simple example:
<?php use Peso\Peso\CurrencyConverter; use Peso\Services\EuropeanCentralBankService; require __DIR__ . '/vendor/autoload.php'; // caching omitted for simplicity $peso = new CurrencyConverter(new EuropeanCentralBankService()); echo $peso->getHistoricalExchangeRate( 'EUR', // base 'PHP', // quote '2025-06-13', // date (Y-m-d string or DateTime or arokettu/date Date) ), PHP_EOL; // '64.706'
Advantages over the Exchanger:
Caching moved to the Service side making it more effective
No way for a service to mistake a historical exchange rate request with a current exchange rate request
Also currency conversion requests for services that support them
Ability to add new request types without breaking the backward compatibility
Services reside in their own separate packages so the main package is not a huge garbage dump of dead or unsupported services like Cryptonator
Comments
Comments powered by Disqus