1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-05 16:17:28 +02:00

refactor: deprecate FeedItem constructor (#4201)

* fix: bug in prior commit

* refactor: deprecate FeedItem constructor

* test: fix
This commit is contained in:
Dag
2024-08-08 03:43:26 +02:00
committed by GitHub
parent 2a96bf19b5
commit 6afd13eb06
11 changed files with 78 additions and 114 deletions

View File

@@ -12,10 +12,6 @@ class FeedItem
protected ?string $uid = null;
protected array $misc = [];
public function __construct()
{
}
public static function fromArray(array $itemArray): self
{
$item = new self();
@@ -25,6 +21,10 @@ class FeedItem
return $item;
}
private function __construct()
{
}
public function __set($name, $value)
{
switch ($name) {
@@ -89,18 +89,6 @@ class FeedItem
return $this->uri;
}
/**
* Set URI to the full article.
*
* Use {@see FeedItem::getURI()} to get the URI.
*
* _Note_: Removes whitespace from the beginning and end of the URI.
*
* _Remarks_: Uses the attribute "href" or "src" if the provided URI is an
* object of simple_html_dom_node.
*
* @param simple_html_dom_node|object|string $uri URI to the full article.
*/
public function setURI($uri)
{
$this->uri = null; // Clear previous data

View File

@@ -6,11 +6,11 @@ abstract class FormatAbstract
const MIME_TYPE = 'text/plain';
protected string $charset = 'UTF-8';
protected array $items = [];
protected int $lastModified;
protected array $feed = [];
protected array $items = [];
protected string $charset = 'UTF-8';
protected int $lastModified;
abstract public function stringify();
@@ -30,12 +30,11 @@ abstract class FormatAbstract
return $this->feed;
}
/**
* @param FeedItem[] $items
*/
public function setItems(array $items): void
{
$this->items = $items;
foreach ($items as $item) {
$this->items[] = FeedItem::fromArray($item);
}
}
/**

View File

@@ -422,9 +422,18 @@ abstract class XPathAbstract extends BridgeAbstract
}
foreach ($entries as $entry) {
$item = new FeedItem();
foreach (['title', 'content', 'uri', 'author', 'timestamp', 'enclosures', 'categories'] as $param) {
$expression = $this->getParam($param);
$item = [];
$parameters = [
'title',
'content',
'uri',
'author',
'timestamp',
'enclosures',
'categories',
];
foreach ($parameters as $parameter) {
$expression = $this->getParam($parameter);
if ('' === $expression) {
continue;
}
@@ -438,21 +447,21 @@ abstract class XPathAbstract extends BridgeAbstract
continue;
}
if ('categories' === $param && $typedResult instanceof \DOMNodeList) {
if ('categories' === $parameter && $typedResult instanceof \DOMNodeList) {
$value = [];
foreach ($typedResult as $domNode) {
$value[] = $this->getItemValueOrNodeValue($domNode, false);
}
} else {
$value = $this->getItemValueOrNodeValue($typedResult, 'content' === $param);
$value = $this->getItemValueOrNodeValue($typedResult, 'content' === $parameter);
}
$item->__set($param, $this->formatParamValue($param, $value));
$item[$parameter] = $this->formatParamValue($parameter, $value);
}
$itemId = $this->generateItemId($item);
if (null !== $itemId) {
$item->setUid($itemId);
$item['uid'] = $itemId;
}
$this->items[] = $item;
@@ -646,10 +655,9 @@ abstract class XPathAbstract extends BridgeAbstract
/**
* Allows overriding default mechanism determining items Uid's
*
* @param FeedItem $item
* @return string|null
*/
protected function generateItemId(FeedItem $item)
protected function generateItemId(array $item)
{
return null;
}