Skip to content

Commit 79ed074

Browse files
author
Harrison Ifeanyichukwu
committed
feat: create the ATOM feed class model, all atom feeds are instances of this class
It provides the appropriate namespace mapping, property alternate xpath selector maps that are appropriate for parsing atom feeds
1 parent 6231913 commit 79ed074

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/Feeds/ATOMFeed.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace Forensic\FeedParser\Feeds;
5+
6+
use Forensic\FeedParser\Enums\FeedTypes;
7+
use Forensic\FeedParser\XPath;
8+
use Forensic\FeedParser\FeedItems\ATOMFeedItem;
9+
10+
class ATOMFeed extends BaseFeed
11+
{
12+
public function __construct(XPath $xpath, string $default_lang,
13+
bool $remove_styles, bool $remove_scripts)
14+
{
15+
$namespaces = [
16+
'atom' => 'http://www.w3.org/2005/Atom',
17+
'xml' => 'http://www.w3.org/XML/1998/namespace'
18+
];
19+
20+
$property_selectors = [
21+
'id' => 'atom:id',
22+
'title' => 'atom:title', // text construct
23+
'link' => 'atom:link[@rel="alternate"]/@href || atom:link/@href',
24+
'description' => 'atom:subtitle', // text construct
25+
'image' => [
26+
'src' => 'atom:logo',
27+
'link' => 'atom:link',
28+
'title' => 'atom:title'
29+
],
30+
'copyright' => 'atom:rights',
31+
'publisher' => 'atom:contributor || atom:title',
32+
'lastUpdated' => 'atom:updated',
33+
'creator' => 'atom:generator',
34+
'language' => '@xml:lang',
35+
'category' => 'atom:category'
36+
];
37+
38+
$items_selector = 'atom:entry';
39+
40+
parent::__construct(
41+
new FeedTypes(FeedTypes::ATOM_FEED),
42+
$default_lang,
43+
$xpath,
44+
$namespaces,
45+
$property_selectors,
46+
$items_selector,
47+
$remove_styles,
48+
$remove_scripts
49+
);
50+
}
51+
}

0 commit comments

Comments
 (0)