providers) and isset($this->providers[$name]) and in_array($provider, $this->providers[$name])) { return $this; } if (!isset($this->providers[$name])) { $this->providers[$name] = []; } $this->providers[$name] []= $provider; return $this; } public function getProviders(string $name): array { return $this->providers[$name]; } public function get(string $provider, DateTimeInterface $dateTime): float { $providers = $this->getProviders($provider); 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('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('ipc'); foreach ($providers as $provider) { try { return $provider->getVar($start, $end); } catch (EmptyResponse $exception) { $this->logger->notice($exception); } } return 0; } public function getUSD(DateTimeInterface $dateTime): float { $providers = $this->getProviders('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; } }