mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 09:14:08 +00:00
Replace duplicated switch/case blocks across 4 methods with a clean abstract driver pattern: - ExchangeRateDriver (abstract): defines getExchangeRate(), getSupportedCurrencies(), validateConnection() - CurrencyFreakDriver, CurrencyLayerDriver, OpenExchangeRateDriver, CurrencyConverterDriver: concrete implementations - ExchangeRateDriverFactory: resolves driver name to class, with register() method for module extensibility Delete ExchangeRateProvidersTrait — all logic now lives in driver classes and ExchangeRateProviderService. Adding a new exchange rate provider only requires implementing ExchangeRateDriver and calling ExchangeRateDriverFactory::register() in a module service provider.
35 lines
845 B
PHP
35 lines
845 B
PHP
<?php
|
|
|
|
namespace App\Services\ExchangeRate;
|
|
|
|
abstract class ExchangeRateDriver
|
|
{
|
|
public function __construct(
|
|
protected string $apiKey,
|
|
protected array $config = [],
|
|
) {}
|
|
|
|
/**
|
|
* Fetch exchange rate between two currencies.
|
|
*
|
|
* @return array Exchange rate values
|
|
*/
|
|
abstract public function getExchangeRate(string $baseCurrency, string $targetCurrency): array;
|
|
|
|
/**
|
|
* Get list of currencies supported by this provider.
|
|
*
|
|
* @return array Currency codes
|
|
*/
|
|
abstract public function getSupportedCurrencies(): array;
|
|
|
|
/**
|
|
* Validate that the API key and connection work.
|
|
*
|
|
* @return array Exchange rate values (proof of working connection)
|
|
*
|
|
* @throws ExchangeRateException
|
|
*/
|
|
abstract public function validateConnection(): array;
|
|
}
|