/** * @param Locale $locale * @param int $limit * @return array */ private function fetchRssFeedData(Locale $locale, $limit = 5) { $lang = 'de'; if ($locale->getLocale() != 'de_DE') { $lang = 'en'; } $result = []; try { $xml = new \SimpleXMLElement(file_get_contents('https://' . $lang . '.shopware.com/news/?sRss=1', false, stream_context_create(['http' => ['timeout' => 20]]))); } catch (Exception $e) { return $result; } /** * @var \SimpleXMLElement $news */ foreach ($xml->channel->item as $news) { $tmp = (array) $news->children(); $date = new \DateTime($tmp['pubDate']); $result[] = ['title' => $tmp['title'], 'link' => $tmp['link'], 'linkHash' => md5($tmp['link']), 'pubDate' => $date->format('Y-m-d\\TH:i:s')]; } if ($limit) { $result = array_slice($result, 0, $limit); } return $result; }
/** * {@inheritDoc} */ public function getLocale() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getLocale', array()); return parent::getLocale(); }