Download the PHP package azaharizaman/nexus-currency without Composer
On this page you can find all versions of the php package azaharizaman/nexus-currency. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download azaharizaman/nexus-currency
More information about azaharizaman/nexus-currency
Files in azaharizaman/nexus-currency
Package nexus-currency
Short Description Framework-agnostic ISO 4217-compliant currency management and exchange rate engine for the Nexus ERP system
License MIT
Informations about the package nexus-currency
Nexus\Currency
Framework-agnostic ISO 4217-compliant currency management and exchange rate engine for the Nexus ERP system.
Overview
The Nexus\Currency package provides authoritative currency metadata and exchange rate management following ISO 4217 standards. It complements the existing Nexus\Finance\ValueObjects\Money implementation by providing validation, formatting, and exchange rate coordination without replacing core financial value objects.
Key Features
- ISO 4217 Compliance: Full support for international currency standards
- Decimal Precision Rules: Correct handling of 0-decimal (JPY), 2-decimal (USD), and 3-decimal (BHD) currencies
- Exchange Rate Management: Pluggable provider architecture for external rate APIs
- Intelligent Caching: Configurable rate storage to minimize API calls
- Framework-Agnostic: Pure PHP with no Laravel dependencies
- BCMath Compatible: Designed to work with high-precision monetary calculations
- Stateless Design: All services are stateless and horizontally scalable
Architecture
This package follows the "Logic in Packages, Implementation in Applications" pattern:
Integration with Nexus\Finance
The Nexus\Currency package augments (not replaces) existing financial components:
Nexus\Finance\ValueObjects\Moneyremains the core monetary value objectNexus\Finance\ValueObjects\ExchangeRateremains the core rate value objectNexus\Currencyprovides:- Currency metadata (symbols, names, decimal rules)
- Currency code validation
- Exchange rate provider coordination
- Formatting utilities
What This Package Provides
CurrencyManager: High-level currency operations (validation, formatting, metadata)ExchangeRateService: Exchange rate lookup with caching and conversion- Value Objects:
Currency(metadata),CurrencyPair(pair representation) - Contracts: Repository, Provider, and Storage interfaces
- Exceptions: Domain-specific errors with static factories
What the Application Must Implement
The consuming application (Nexus\Atomy) must provide:
- Currency Repository: Database-backed implementation with ISO 4217 seed data
- Exchange Rate Provider: Integration with external APIs (ECB, Fixer.io, etc.) using
Nexus\Connector - Rate Storage: Redis/Database caching implementation
- Service Bindings: IoC container bindings in service provider
Installation
Requirements
- PHP 8.3 or higher
- BCMath extension (for precision calculations)
- PSR-3 Logger implementation (optional)
Core Components
1. Currency Value Object
Immutable representation of ISO 4217 currency metadata:
2. CurrencyPair Value Object
Represents a currency exchange pair:
3. CurrencyManager Service
High-level currency management:
4. ExchangeRateService
Exchange rate lookup and conversion:
Application Integration
Step 1: Implement Currency Repository
Create a database-backed repository in apps/Atomy:
Step 2: Create Database Migration
Step 3: Seed ISO 4217 Data
Step 4: Implement Exchange Rate Provider
Using Nexus\Connector for resilient API integration:
Step 5: Implement Rate Storage (Redis)
Step 6: Bind Implementations in Service Provider
Integration with Nexus\Finance
Enhancing Money Validation
Update Nexus\Finance\ValueObjects\Money to use CurrencyManager:
Currency-Aware Formatting
Add a formatting method to Money that uses currency metadata:
Usage:
Decimal Precision Strategy
The 4-Decimal Internal Standard
Nexus\Finance\ValueObjects\Money uses 4 decimal places for all internal BCMath calculations:
Why 4 decimals internally?
- Prevents rounding errors in complex calculations (tax, interest, multi-step conversions)
- Allows accurate intermediate results for financial operations
- Industry standard for accounting systems
Currency-Specific Display Precision
Nexus\Currency provides the correct display precision per ISO 4217:
Best Practice: Calculate at 4, Display per Currency
Error Handling
All exceptions provide static factory methods for contextual error messages:
Testing
Unit Testing with In-Memory Repository
For package unit tests, create a simple in-memory implementation:
Documentation
📚 Complete Documentation
- Getting Started Guide - Quick start, installation, and basic configuration
- API Reference - Complete interface and method documentation
- Integration Guide - Laravel, Symfony, and custom framework integration
- Code Examples - Practical usage examples
- Basic Usage - Currency validation, formatting, and retrieval
- Advanced Usage - Exchange rates, conversion, and caching
- Requirements - Detailed functional and architectural requirements
- Implementation Summary - Development progress and metrics
- Test Suite Summary - Testing strategy and coverage
- Valuation Matrix - Package valuation and ROI metrics
🔗 Quick Links
| Documentation | Description |
|---|---|
| Prerequisites | System requirements and dependencies |
| Core Concepts | ISO 4217, non-breaking augmentation, caching |
| Configuration Steps | Complete setup guide |
| Laravel Integration | Laravel migrations, repositories, service providers |
| Symfony Integration | Symfony entities, services, configuration |
| Testing Examples | Unit and integration test examples |
| Troubleshooting | Common issues and solutions |
License
MIT License - see LICENSE file for details.
Credits
Developed by the Nexus Development Team for the Nexus ERP System.
Related Packages
- Nexus\Finance - Core financial value objects (Money, ExchangeRate)
- Nexus\Accounting - Multi-currency financial statements
- Nexus\Connector - Resilient API integration with circuit breaker
- Nexus\Tenant - Multi-tenancy with per-tenant base currency