/** * {@inheritdoc} */ public function fetch($sourceName = null, \DateTime $date = null) { $rates = array(); $sourceNames = $sourceName === null ? array_map(function (SourceInterface $source) { return $source->getName(); }, $this->sources->all()) : (array) $sourceName; foreach ($sourceNames as $sourceName) { $source = $this->sources->get($sourceName); $configurations = $this->configurations->all(array('sourceName' => $sourceName)); /** * @var Configuration $configuration */ foreach ($configurations as $configuration) { $rates[] = $source->fetch($configuration->getCurrencyCode(), $configuration->getRateType(), $date); } } /** * @var ProcessorInterface $processor */ foreach ($this->processors->all() as $processor) { $rates = $processor->process($this->baseCurrency, $this->configurations, $rates); } $this->repository->save($rates); return $rates; }
/** * Clean sources from console input. * * @param InputInterface $input Console input. * @param OutputStyle $outputStyle Output style to use. * @return FetchCommand $this Fluent interface. * * @throws \Exception */ protected function cleanInputSources(InputInterface $input, OutputStyle $outputStyle) { $sources = $input->getOption('source'); if (!empty($sources)) { $sources = array_map('trim', explode(',', $sources)); foreach ($sources as $source) { if (!$this->sourcesRegistry->has($source)) { $outputStyle->error(sprintf('Invalid source name "%s" provided, available sources are "%s".', $source, implode(', ', array_map(function (SourceInterface $source) { return $source->getName(); }, $this->sourcesRegistry->all())))); throw new \Exception(); } } } $input->setOption('source', $sources); return $this; }