From 6e66c3974f9df8aeaef2fe6bc302672279a36080 Mon Sep 17 00:00:00 2001 From: Catalin Vasiliu Date: Fri, 6 Oct 2023 14:05:44 +0300 Subject: [PATCH] add configs for api-exchange --- config/api-exchangerate.php | 6 ++++++ src/CurrencyServiceProvider.php | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 config/api-exchangerate.php diff --git a/config/api-exchangerate.php b/config/api-exchangerate.php new file mode 100644 index 0000000..cc05a09 --- /dev/null +++ b/config/api-exchangerate.php @@ -0,0 +1,6 @@ + env('API_EXCHANGE_API_KEY', 'test'), + 'base_url' => env('API_EXCHANGE_BASE_URL', 'https://api.exchangerate.host'), +]; diff --git a/src/CurrencyServiceProvider.php b/src/CurrencyServiceProvider.php index f3fa823..5a69248 100644 --- a/src/CurrencyServiceProvider.php +++ b/src/CurrencyServiceProvider.php @@ -3,6 +3,7 @@ namespace AmrShawky\LaravelCurrency; use AmrShawky\CurrencyFactory; +use Illuminate\Foundation\Application as LaravelApplication; use Illuminate\Support\ServiceProvider; class CurrencyServiceProvider extends ServiceProvider @@ -10,12 +11,23 @@ class CurrencyServiceProvider extends ServiceProvider public function register() { $this->app->bind('Currency', function ($app) { - return new CurrencyFactory(); + return new CurrencyFactory($app->config->get('api-exchangerate')); }); } public function boot() { + $this->setupConfig(); + } + protected function setupConfig(): void + { + $source = realpath(__DIR__.'/../config/api-exchangerate.php'); + if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { + $this->publishes([$source => config_path('api-exchangerate.php')]); + } elseif ($this->app instanceof LumenApplication) { + $this->app->configure('api-exchangerate'); + } + $this->mergeConfigFrom($source, 'api-exchangerate'); } } \ No newline at end of file