10 defined(
'JPATH_PLATFORM') or die;
25 protected $parsers = array(
'rss' =>
'JFeedParserRss',
'feed' =>
'JFeedParserAtom');
38 public function getFeed($uri)
41 $reader =
new XMLReader;
44 if (!$reader->open($uri, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING))
46 throw new RuntimeException(
'Unable to open the feed.');
56 while ($reader->nodeType !== XMLReader::ELEMENT);
60 throw new RuntimeException(
'Error reading feed.');
64 $parser = $this->_fetchFeedParser($reader->name, $reader);
66 return $parser->parse();
81 public function registerParser($tagName, $className, $overwrite =
false)
84 if (!class_exists($className))
86 throw new InvalidArgumentException(
'The feed parser class ' . $className .
' does not exist.');
90 if (!preg_match(
'/\A(?!XML)[a-z][\w0-9-]*/i', $tagName))
92 throw new InvalidArgumentException(
'The tag name ' . $tagName .
' is not valid.');
96 if (empty($this->parsers[$tagName]) || (
bool) $overwrite)
98 $this->parsers[(string) $tagName] = (
string) $className;
115 private function _fetchFeedParser($type, XMLReader $reader)
118 if (empty($this->parsers[$type]))
120 throw new LogicException(
'No registered feed parser for type ' . $type .
'.');
123 return new $this->parsers[$type]($reader);