FleetCart/Modules/Currency/Console/RefreshCurrencyRatesCommand.php

62 lines
1.3 KiB
PHP
Raw Normal View History

2023-06-11 12:14:03 +00:00
<?php
namespace Modules\Currency\Console;
use Illuminate\Console\Command;
use Modules\Currency\Entities\CurrencyRate;
use Modules\Currency\Services\CurrencyRateExchanger;
class RefreshCurrencyRatesCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'currency:refresh-rates';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Refresh currency rates.';
/**
* The currency rate exchanger instance.
*
2023-12-03 14:07:47 +00:00
* @var CurrencyRateExchanger
2023-06-11 12:14:03 +00:00
*/
private $exchanger;
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
/**
* Create a new command instance.
*
2023-12-03 14:07:47 +00:00
* @param CurrencyRateExchanger $exchanger
*
2023-06-11 12:14:03 +00:00
* @return void
*/
public function __construct(CurrencyRateExchanger $exchanger)
{
parent::__construct();
$this->exchanger = $exchanger;
}
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (is_null(setting('currency_rate_exchange_service'))) {
return logger()->error('RefreshCurrencyRatesCommand: Currency rate exchange service is not configured.');
}
CurrencyRate::refreshRates($this->exchanger);
}
}