|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Orkhanahmadov\LaravelCurrencylayer; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
|
6
|
|
|
use Orkhanahmadov\Currencylayer\Client; |
|
7
|
|
|
use Orkhanahmadov\Currencylayer\CurrencylayerClient; |
|
8
|
|
|
use Orkhanahmadov\LaravelCurrencylayer\Commands\LiveCommand; |
|
9
|
|
|
use Orkhanahmadov\LaravelCurrencylayer\Commands\RateCommand; |
|
10
|
|
|
use Orkhanahmadov\LaravelCurrencylayer\Contracts\CurrencyService; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @codeCoverageIgnore |
|
14
|
|
|
*/ |
|
15
|
|
|
class LaravelCurrencylayerServiceProvider extends ServiceProvider |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Bootstrap the application services. |
|
19
|
|
|
*/ |
|
20
|
|
|
public function boot(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->app->bind(Client::class, static function () { |
|
23
|
|
|
return new CurrencylayerClient( |
|
24
|
|
|
config('currencylayer.access_key'), |
|
25
|
|
|
config('currencylayer.https_connection') |
|
26
|
|
|
); |
|
27
|
|
|
}); |
|
28
|
|
|
$this->app->bind(CurrencyService::class, Currencylayer::class); |
|
29
|
|
|
|
|
30
|
|
|
if ($this->app->runningInConsole()) { |
|
31
|
|
|
$this->publishes([ |
|
32
|
|
|
__DIR__.'/../config/config.php' => config_path('currencylayer.php'), |
|
33
|
|
|
], 'config'); |
|
34
|
|
|
|
|
35
|
|
|
if (! class_exists('CreateCurrencylayerCurrenciesTable') && |
|
36
|
|
|
! class_exists('CreateCurrencylayerRatesTable') |
|
37
|
|
|
) { |
|
38
|
|
|
$this->publishes([ |
|
39
|
|
|
__DIR__.'/../database/migrations/create_currencylayer_currencies_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_currencylayer_currencies_table.php'), |
|
40
|
|
|
__DIR__.'/../database/migrations/create_currencylayer_rates_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_currencylayer_rates_table.php'), |
|
41
|
|
|
], 'migrations'); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Register the application services. |
|
48
|
|
|
*/ |
|
49
|
|
|
public function register(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'currencylayer'); |
|
52
|
|
|
|
|
53
|
|
|
$this->app->singleton('currencylayer', static function () { |
|
54
|
|
|
return new Currencylayer(new CurrencylayerClient( |
|
55
|
|
|
config('currencylayer.access_key'), |
|
56
|
|
|
config('currencylayer.https_connection') |
|
57
|
|
|
)); |
|
58
|
|
|
}); |
|
59
|
|
|
|
|
60
|
|
|
if ($this->app->runningInConsole()) { |
|
61
|
|
|
$this->commands([ |
|
62
|
|
|
LiveCommand::class, |
|
63
|
|
|
RateCommand::class, |
|
64
|
|
|
]); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|