Download the PHP package lemonade/component_currency without Composer
On this page you can find all versions of the php package lemonade/component_currency. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lemonade/component_currency
More information about lemonade/component_currency
Files in lemonade/component_currency
Package component_currency
Short Description Typed PHP currency conversion library using Czech National Bank exchange rates, filesystem cache, fallback values, and a lightweight hexagonal architecture.
License MIT
Homepage https://github.com/johnnyxlemonade/component_currency
Informations about the package component_currency
Lemonade Currency Conversion Library
Lemonade Currency Conversion Library provides a general-purpose currency converter using the Czech National Bank (CNB) as the primary data source.
The library exposes a simple developer-friendly API while internally using a layered, hexagonal-style architecture. This keeps the public API stable and easy to use, while infrastructure concerns such as CNB fetching, parsing, caching, and time resolution stay isolated behind explicit ports and adapters.
Features
- Supports PHP 8.1+
- Fully typed and optimized for static analysis with PHPStan Level 10, strict rules, and bleeding edge
- Provides exchange rates and currency values for supported currencies
- Uses the Czech National Bank (CNB) as the primary data source
- Caches CNB yearly exchange-rate data in the filesystem
- Falls back to default values when CNB data is unavailable
- Supports nearest previous available rate lookup
- Automatically adjusts to CNB's publishing schedule:
- Exchange rates are published on working days after 14:30.
- Before 14:30, the previous day's rates are used as the current rate.
- Provides a backward-compatible facade API for simple usage
Supported Data Sources
- Czech National Bank (CNB)
Supported Currencies
- CZK - Czech Republic
- EUR - Eurozone
- HUF - Hungary
- PLN - Poland
- GBP - Great Britain
- USD - United States
Installation
Use Composer to install the library:
Architecture
The library is organized using a lightweight hexagonal architecture.
Domain
The domain layer contains the core currency model and rules:
- supported currency codes
- default currency values
- currency metadata such as symbols and names
- parsed exchange-rate table representation
It does not depend on CNB, filesystem, HTTP, or runtime environment.
Application
The application layer contains the main use case:
- resolving the requested date
- applying CNB publishing-time rules
- reading rates from cache
- fetching rates from the configured source
- parsing CNB data
- falling back to default values when needed
The primary service is:
Ports
Ports define contracts for external concerns:
This allows custom implementations for fetching rates, caching data, or controlling time in tests.
Infrastructure
Infrastructure contains concrete adapters:
CnbExchangeRateSourcefetches CNB dataCnbRateParserparses CNB text dataFileExchangeRateCachestores CNB data in the filesystemSystemClockprovides current runtime timeRegexLineSplittersplits CNB text data into lines
Facade API
The public facade classes remain available for simple usage and backward compatibility:
Usage
Basic static API
CurrencyCode enum
Shortcut methods
Market object API
String currency codes are still supported for backward compatibility.
Currency metadata
Advanced Usage
Custom storage directory
By default, the library stores CNB cache files in:
You can create the application service manually with a custom storage directory:
Custom cache, source, parser, or clock
For full control, instantiate the application service directly:
This is useful when integrating the library into applications that already have their own cache layer, HTTP transport, or deterministic clock.
Custom exchange-rate source
Implement the ExchangeRateSource port to fetch data from a different source.
CNB Data Notes
CNB yearly exchange-rate data uses multipliers in the header, for example:
The parser normalizes values to a single currency unit. For example, 100 HUF with value 6,505 is stored as 0.06505 per 1 HUF.
Configuration
The default filesystem cache directory is:
Ensure this directory is writable by the PHP process when using the default service factory.
Testing
Run unit tests:
Run static analysis:
Quality
The library is designed for:
- strict typing
- PHPStan Level 10
- strict rules
- bleeding-edge static analysis
- isolated domain logic
- testable infrastructure adapters
- stable backward-compatible facade API
Contributing
Feel free to submit issues or create pull requests to improve this library.
License
This library is licensed under the MIT License. See the LICENSE file for details.