Skip to content

Commit 6041f8b

Browse files
author
Harrison Ifeanyichukwu
committed
feat: create the parse interface, handle feed malformedness and unsupported feed formats
1 parent e232b0a commit 6041f8b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/Parser.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Forensic\FeedParser\Exceptions\InvalidURLException;
1515
use Forensic\FeedParser\Exceptions\ResourceNotFoundException;
1616
use Forensic\FeedParser\Exceptions\FileNotFoundException;
17+
use Forensic\FeedParser\Exceptions\MalformedFeedException;
18+
use Forensic\FeedParser\Exceptions\FeedTypeNotSupportedException;
1719

1820
/**
1921
* Class Parser
@@ -49,7 +51,34 @@ public function getDefaultLanguage()
4951
*/
5052
private function parse(string $xml)
5153
{
52-
return null;
54+
$xml_instance = new XML($xml);
55+
if (!$xml_instance->status())
56+
throw new MalformedFeedException(implode("\n", $xml_instance->errors()));
57+
58+
$doc = $xml_instance->document();
59+
$xpath = new XPath($doc);
60+
61+
$result = null;
62+
63+
//inspect feed type
64+
$feed_name = explode(':', $doc->documentElement->tagName)[0];
65+
switch(strtolower($feed_name))
66+
{
67+
case 'feed':
68+
$result = null;
69+
break;
70+
case 'rss':
71+
$result = null;
72+
break;
73+
case 'rdf':
74+
$result = null;
75+
break;
76+
default:
77+
$message = $feed_name . ' feed type is currently not support';
78+
throw new FeedTypeNotSupportedException($message);
79+
break;
80+
}
81+
return $result;
5382
}
5483

5584
/**

0 commit comments

Comments
 (0)