Changeset View
Changeset View
Standalone View
Standalone View
src/app/Utils.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use Carbon\Carbon; | use Carbon\Carbon; | ||||
use Illuminate\Support\Facades\Auth; | use Illuminate\Support\Facades\Auth; | ||||
use Ramsey\Uuid\Uuid; | use Ramsey\Uuid\Uuid; | ||||
use Illuminate\Support\Facades\Cache; | |||||
/** | /** | ||||
* Small utility functions for App. | * Small utility functions for App. | ||||
*/ | */ | ||||
class Utils | class Utils | ||||
{ | { | ||||
// Note: Removed '0', 'O', '1', 'I' as problematic with some fonts | // Note: Removed '0', 'O', '1', 'I' as problematic with some fonts | ||||
public const CHARS = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'; | public const CHARS = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'; | ||||
▲ Show 20 Lines • Show All 385 Lines • ▼ Show 20 Lines | public static function uiEnv(): array | ||||
$menu = $theme['menu']; | $menu = $theme['menu']; | ||||
} | } | ||||
} | } | ||||
$env['menu'] = $menu; | $env['menu'] = $menu; | ||||
return $env; | return $env; | ||||
} | } | ||||
/** | |||||
* Retrieve an exchange rate. | |||||
* | |||||
* @param string $sourceCurrency: Currency from which to convert | |||||
* @param string $targetCurrency: Currency to convert to | |||||
machniak: Again, the phpdoc formatting is not correct. | |||||
* | |||||
* @return float Exchange rate | |||||
*/ | |||||
public static function exchangeRate(string $sourceCurrency, string $targetCurrency): float | |||||
{ | |||||
$rates = include resource_path("exchangerates-$sourceCurrency.php"); | |||||
if (!isset($rates[$targetCurrency])) { | |||||
throw new \Exception("Failed to find exchange rate for " . $targetCurrency); | |||||
} | |||||
return floatval($rates[$targetCurrency]); | |||||
} | |||||
} | } | ||||
Done Inline ActionsI think Jeroen and I would prefer to do this differently. When fetching the exchange rates we rather use cron and store the rates in a file (or DB). This way a failing request to openexchangerates website does not cause issues for our users. In such cases we'd just use the old rates instead of throwing an exception. machniak: I think Jeroen and I would prefer to do this differently. When fetching the exchange rates we… | |||||
Done Inline ActionsSo is that a data:import:exchangerate artisan command? How do I store and load something like the exchangerates in the db best? mollekopf: So is that a data:import:exchangerate artisan command?
How do I store and load something like… | |||||
Done Inline ActionsI think I could follow either what ip4net does and store it in the db or what countriescommand does and store it in a file. Up to you. mollekopf: I think I could follow either what ip4net does and store it in the db or what countriescommand… | |||||
Done Inline ActionsI think a file would be fine. machniak: I think a file would be fine. |
Again, the phpdoc formatting is not correct.