providers)) { return $this; } $this->providers []= $provider; return $this; } public function getProviders(string $name): array { return array_values(array_filter($this->providers, fn($provider) => $provider->supported($name))); } public function get(string $name, DateTimeInterface $dateTime): float { $providers = $this->getProviders($name); foreach ($providers as $provider) { try { return $provider->get(self::getSymbol($provider), $dateTime); } catch (EmptyResponse $exception) { $this->logger->notice($exception); } } return 0; } public function getUF(?DateTimeInterface $dateTime = null): float { $providers = $this->getProviders(self::UF); foreach ($providers as $provider) { try { return $provider->get(self::UF, $dateTime); } catch (EmptyResponse $exception) { $this->logger->notice($exception); } } return 0; } public function getIPC(DateTimeInterface $start, DateTimeInterface $end): float { if ($start >= $end) { return 0; } $providers = $this->getProviders(self::IPC); foreach ($providers as $provider) { try { if (method_exists($provider, 'getVar')) { return $provider->getVar($start, $end); } return $provider->get(self::IPC, $end); } catch (EmptyResponse $exception) { $this->logger->notice($exception); } } return 0; } public function getUSD(DateTimeInterface $dateTime): float { $providers = $this->getProviders(self::USD); foreach ($providers as $provider) { try { return $provider->get(self::USD, $dateTime); } catch (EmptyResponse $exception) { $this->logger->notice($exception); } } return 0; } public static function getSymbol(string $identifier): string { $upper = strtoupper($identifier); $output = ''; eval("\$output = self::{$upper};"); return $output; } }