aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Dag <me@dvikan.no> 2024-08-08 03:43:26 +0200
committerGravatar GitHub <noreply@github.com> 2024-08-08 03:43:26 +0200
commit6afd13eb06276f085f245c5075972ef36eb6740a (patch)
tree6a4e676fe3ec01c921e4e58c344e7263fffe45c2 /lib
parent2a96bf19b5354ceecb417f266070b9659d08e84a (diff)
downloadrss-bridge-6afd13eb06276f085f245c5075972ef36eb6740a.tar.gz
rss-bridge-6afd13eb06276f085f245c5075972ef36eb6740a.tar.zst
rss-bridge-6afd13eb06276f085f245c5075972ef36eb6740a.zip
refactor: deprecate FeedItem constructor (#4201)
* fix: bug in prior commit * refactor: deprecate FeedItem constructor * test: fix
Diffstat (limited to 'lib')
-rw-r--r--lib/FeedItem.php20
-rw-r--r--lib/FormatAbstract.php13
-rw-r--r--lib/XPathAbstract.php26
3 files changed, 27 insertions, 32 deletions
diff --git a/lib/FeedItem.php b/lib/FeedItem.php
index 8a092a27..bca06c23 100644
--- a/lib/FeedItem.php
+++ b/lib/FeedItem.php
@@ -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
diff --git a/lib/FormatAbstract.php b/lib/FormatAbstract.php
index 28eb4bbf..9cba0d8c 100644
--- a/lib/FormatAbstract.php
+++ b/lib/FormatAbstract.php
@@ -6,11 +6,11 @@ abstract class FormatAbstract
const MIME_TYPE = 'text/plain';
- protected string $charset = 'UTF-8';
+ protected array $feed = [];
protected array $items = [];
- protected int $lastModified;
+ protected string $charset = 'UTF-8';
- protected array $feed = [];
+ 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);
+ }
}
/**
diff --git a/lib/XPathAbstract.php b/lib/XPathAbstract.php
index 6163ca13..44cbab67 100644
--- a/lib/XPathAbstract.php
+++ b/lib/XPathAbstract.php
@@ -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;
}