Files
investbrain/app/Interfaces/MarketData/FallbackInterface.php
T

45 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2025-01-28 17:33:54 -06:00
declare(strict_types=1);
namespace App\Interfaces\MarketData;
use Illuminate\Support\Facades\Log;
class FallbackInterface
{
protected string $latest_error;
public function __call($method, $arguments)
{
$providers = explode(',', config('investbrain.provider', 'yahoo'));
2025-01-28 17:14:49 -06:00
foreach ($providers as $provider) {
$provider = trim($provider);
try {
Log::warning("Calling method {$method} ({$provider})");
2025-01-28 17:14:49 -06:00
if (! in_array($provider, array_keys(config('investbrain.interfaces', [])))) {
throw new \Exception("Provider [{$provider}] is not a valid market data interface.");
}
$provider_class_name = config("investbrain.interfaces.$provider");
return app()->make($provider_class_name)->$method(...$arguments);
} catch (\Throwable $e) {
2025-01-28 17:14:49 -06:00
$this->latest_error = $e->getMessage();
Log::warning("Failed calling method {$method} ({$provider}): {$this->latest_error}");
}
}
throw new \Exception("Could not get market data: {$this->latest_error}");
}
}