Bolt\Controller\Async\General::fetchNews PHP Method

fetchNews() private method

Get the news from Bolt HQ.
private fetchNews ( string $hostname ) : array
$hostname string
return array
    private function fetchNews($hostname)
    {
        $source = $this->getOption('general/branding/news_source', 'http://news.bolt.cm/');
        $options = $this->fetchNewsOptions($hostname);
        $this->app['logger.system']->info('Fetching from remote server: ' . $source, ['event' => 'news']);
        try {
            $fetchedNewsData = (string) $this->app['guzzle.client']->get($source, $options)->getBody(true);
        } catch (RequestException $e) {
            $this->app['logger.system']->error('Error occurred during newsfeed fetch', ['event' => 'exception', 'exception' => $e]);
            return ['error' => ['type' => 'error', 'title' => 'Unable to fetch news!', 'teaser' => "<p>Unable to connect to {$source}</p>"]];
        }
        $fetchedNewsItems = json_decode($fetchedNewsData);
        if ($newsVariable = $this->getOption('general/branding/news_variable')) {
            $fetchedNewsItems = $fetchedNewsItems->{$newsVariable};
        }
        $news = [];
        if (!$fetchedNewsItems) {
            $this->app['logger.system']->error('Invalid JSON feed returned', ['event' => 'news']);
            return $news;
        }
        // Iterate over the items, pick the first news-item that
        // applies and the first alert we need to show
        foreach ($fetchedNewsItems as $item) {
            $type = $item->type === 'alert' ? 'alert' : 'information';
            if (!isset($news[$type]) && (empty($item->target_version) || Bolt\Version::compare($item->target_version, '>'))) {
                $news[$type] = $item;
            }
        }
        return $news;
    }