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