Skip to content
This repository was archived by the owner on Oct 14, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/api-exchangerate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
'access_key' => env('API_EXCHANGE_API_KEY', 'test'),
'base_url' => env('API_EXCHANGE_BASE_URL', 'https://api.exchangerate.host'),
];
14 changes: 13 additions & 1 deletion src/CurrencyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@
namespace AmrShawky\LaravelCurrency;

use AmrShawky\CurrencyFactory;
use Illuminate\Foundation\Application as LaravelApplication;
use Illuminate\Support\ServiceProvider;

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');
}
}