Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/Data/Import/OpenExchangeRatesCommand.php
Show All 21 Lines | class OpenExchangeRatesCommand extends Command | ||||
/** | /** | ||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$sourceCurrency = 'CHF'; | foreach (['CHF', 'EUR'] as $sourceCurrency) { | ||||
$rates = \App\Backends\OpenExchangeRates::retrieveRates($sourceCurrency); | $rates = \App\Backends\OpenExchangeRates::retrieveRates($sourceCurrency); | ||||
// | |||||
// export | |||||
// | |||||
$file = resource_path("exchangerates-$sourceCurrency.php"); | $file = resource_path("exchangerates-$sourceCurrency.php"); | ||||
$out = "<?php return [\n"; | $out = "<?php return [\n"; | ||||
foreach ($rates as $countryCode => $rate) { | foreach ($rates as $countryCode => $rate) { | ||||
$out .= sprintf(" '%s' => '%s',\n", $countryCode, $rate); | $out .= sprintf(" '%s' => '%s',\n", $countryCode, $rate); | ||||
} | } | ||||
$out .= "];\n"; | $out .= "];\n"; | ||||
file_put_contents($file, $out); | file_put_contents($file, $out); | ||||
} | } | ||||
} | } | ||||
} |