/** * @param \SimpleXMLElement $xml * @return array */ public static function fetch(\SimpleXMLElement $xml) { $items = array(); if (isset($xml->channel->item)) { foreach ($xml->channel->item as $item) { $model = new Feed(); $model->title = (string) $item->children()->title; $model->description = (string) $item->children()->description; $model->link = (string) $item->children()->link; $model->pubDate = (string) $item->children()->pubDate; $model->guid = (string) $item->children()->guid; $items[] = $model->toArray(); } } return $items; }
/** * @param mixed $feeds * @return static */ public function parseFeed($feeds) { if ($this->isStoped()) { return $this; } if (!is_array($feeds)) { $feeds = array('default' => $feeds); } foreach ($feeds as $source => $feed) { $items = Feed::fetch((new Curl())->get($feed)->content('xml')); foreach ($items as &$item) { $item['__source'] = $source; } $this->setItems($items); } return $this; }